@mailoo/images 0.0.0-stage → 1.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +45 -2
- package/dist/index.cjs +72 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/routes/index.cjs +229 -0
- package/dist/routes/index.cjs.map +1 -0
- package/dist/routes/index.d.cts +48 -0
- package/dist/routes/index.d.ts +48 -0
- package/dist/routes/index.js +206 -0
- package/dist/routes/index.js.map +1 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Mailoo Integrator Use License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mailoo
|
|
4
|
+
|
|
5
|
+
Permission is granted to use, install, and distribute this software in
|
|
6
|
+
unmodified form, including as a dependency of an application.
|
|
7
|
+
|
|
8
|
+
Modification of this software is not permitted.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
11
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
12
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
13
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
14
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
15
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
16
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@mailoo/images`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Image URL rewrite + Next.js BFF helpers for Mailoo media.
|
|
4
|
+
|
|
5
|
+
## Public embed proxy
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// app/api/mailoo-image/route.ts
|
|
9
|
+
import { createPublicImageContentHandler } from '@mailoo/images/routes'
|
|
10
|
+
|
|
11
|
+
export const GET = createPublicImageContentHandler()
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Defaults to server-only `MAILOO_BLOG_API` / `MAILOO_BLOG_API_KEY` (HTTP
|
|
15
|
+
503 if unset). Pass `getApiBaseUrl` / `getApiKey` to override.
|
|
16
|
+
|
|
17
|
+
When rendering blog HTML:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { rewriteMailooPublicImageUrls } from '@mailoo/images'
|
|
21
|
+
|
|
22
|
+
rewriteMailooPublicImageUrls(html, {
|
|
23
|
+
canonicalPrefixWithIdEquals:
|
|
24
|
+
'https://api.mailoo.app/api/v1/images/public/content?id=',
|
|
25
|
+
proxyPrefixWithIdEquals: 'https://yoursite.com/api/mailoo-image?id=',
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Article cover + HTML + markdown (public avatar URLs are left as-is):
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { rewriteMailooBlogMediaUrls } from '@mailoo/images'
|
|
33
|
+
|
|
34
|
+
rewriteMailooBlogMediaUrls(post, {
|
|
35
|
+
canonicalPrefixWithIdEquals: post.imagePublicEmbedBaseUrl,
|
|
36
|
+
proxyPrefixWithIdEquals: 'https://yoursite.com/api/mailoo-image?id=',
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`ogImageUrl` from the blog API is this canonical embed URL. It is not
|
|
41
|
+
anonymous. Point `og:image` and `<img>` at the proxy URL. The API key needs
|
|
42
|
+
`image.external-read`.
|
|
43
|
+
|
|
44
|
+
## Library BFF (Bearer)
|
|
45
|
+
|
|
46
|
+
Use `createImagesLibraryHandlers({ getApiBaseUrl, getAuthHeader, resolveAuthHeader })`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
escapeRegExp: () => escapeRegExp,
|
|
24
|
+
rewriteMailooBlogMediaUrls: () => rewriteMailooBlogMediaUrls,
|
|
25
|
+
rewriteMailooPublicImageUrls: () => rewriteMailooPublicImageUrls,
|
|
26
|
+
rewriteMailooPublicImageUrlsAnyHost: () => rewriteMailooPublicImageUrlsAnyHost
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
|
|
30
|
+
// src/rewrite.ts
|
|
31
|
+
function escapeRegExp(s) {
|
|
32
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
|
+
}
|
|
34
|
+
var MEDIA_ID_CAPTURE = "([a-z0-9]{20,40})";
|
|
35
|
+
function rewriteMailooPublicImageUrls(content, opts) {
|
|
36
|
+
const from = escapeRegExp(opts.canonicalPrefixWithIdEquals);
|
|
37
|
+
const re = new RegExp(from + MEDIA_ID_CAPTURE, "gi");
|
|
38
|
+
return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`);
|
|
39
|
+
}
|
|
40
|
+
var ANY_HOST_EMBED_PREFIX = /https?:\/\/[^/\s"'<>]+\/api\/v1\/images\/public\/content\?id=/gi;
|
|
41
|
+
function rewriteMailooPublicImageUrlsAnyHost(content, proxyPrefixWithIdEquals) {
|
|
42
|
+
return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/blog-media.ts
|
|
46
|
+
function rewriteMailooBlogMediaUrls(post, opts) {
|
|
47
|
+
const rewrite = (value) => {
|
|
48
|
+
if (typeof value !== "string" || value === "") return value;
|
|
49
|
+
return rewriteMailooPublicImageUrls(value, opts);
|
|
50
|
+
};
|
|
51
|
+
const author = post.author;
|
|
52
|
+
return {
|
|
53
|
+
...post,
|
|
54
|
+
ogImageUrl: rewrite(post.ogImageUrl),
|
|
55
|
+
htmlContent: rewrite(post.htmlContent),
|
|
56
|
+
content: rewrite(post.content),
|
|
57
|
+
...author ? {
|
|
58
|
+
author: {
|
|
59
|
+
...author,
|
|
60
|
+
avatar: rewrite(author.avatar)
|
|
61
|
+
}
|
|
62
|
+
} : {}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
escapeRegExp,
|
|
68
|
+
rewriteMailooBlogMediaUrls,
|
|
69
|
+
rewriteMailooPublicImageUrls,
|
|
70
|
+
rewriteMailooPublicImageUrlsAnyHost
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["export {\n rewriteMailooPublicImageUrls,\n rewriteMailooPublicImageUrlsAnyHost,\n escapeRegExp,\n} from './rewrite.js'\nexport {\n rewriteMailooBlogMediaUrls,\n type MailooImageRewriteOptions,\n} from './blog-media.js'\n","/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;AChBO,SAAS,2BAOd,MAAS,MAAoC;AAC7C,QAAM,UAAU,CACd,UAC8B;AAC9B,QAAI,OAAO,UAAU,YAAY,UAAU,GAAI,QAAO;AACtD,WAAO,6BAA6B,OAAO,IAAI;AAAA,EACjD;AAEA,QAAM,SAAS,KAAK;AACpB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,QAAQ,KAAK,UAAU;AAAA,IACnC,aAAa,QAAQ,KAAK,WAAW;AAAA,IACrC,SAAS,QAAQ,KAAK,OAAO;AAAA,IAC7B,GAAI,SACA;AAAA,MACE,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,QAAQ,QAAQ,OAAO,MAAM;AAAA,MAC/B;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.
|
|
3
|
+
*/
|
|
4
|
+
declare function escapeRegExp(s: string): string;
|
|
5
|
+
declare function rewriteMailooPublicImageUrls(content: string, opts: {
|
|
6
|
+
canonicalPrefixWithIdEquals: string;
|
|
7
|
+
proxyPrefixWithIdEquals: string;
|
|
8
|
+
}): string;
|
|
9
|
+
declare function rewriteMailooPublicImageUrlsAnyHost(content: string, proxyPrefixWithIdEquals: string): string;
|
|
10
|
+
|
|
11
|
+
type MailooImageRewriteOptions = {
|
|
12
|
+
canonicalPrefixWithIdEquals: string;
|
|
13
|
+
proxyPrefixWithIdEquals: string;
|
|
14
|
+
};
|
|
15
|
+
type AuthorWithAvatar = {
|
|
16
|
+
avatar?: string | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Rewrite blog article fields that may contain canonical Mailoo embed URLs.
|
|
20
|
+
* `/api/v1/public/avatars/` URLs are left unchanged (they are already public).
|
|
21
|
+
*/
|
|
22
|
+
declare function rewriteMailooBlogMediaUrls<T extends {
|
|
23
|
+
ogImageUrl?: string | null;
|
|
24
|
+
htmlContent?: string | null;
|
|
25
|
+
content?: string | null;
|
|
26
|
+
author?: (AuthorWithAvatar & object) | null;
|
|
27
|
+
}>(post: T, opts: MailooImageRewriteOptions): T;
|
|
28
|
+
|
|
29
|
+
export { type MailooImageRewriteOptions, escapeRegExp, rewriteMailooBlogMediaUrls, rewriteMailooPublicImageUrls, rewriteMailooPublicImageUrlsAnyHost };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.
|
|
3
|
+
*/
|
|
4
|
+
declare function escapeRegExp(s: string): string;
|
|
5
|
+
declare function rewriteMailooPublicImageUrls(content: string, opts: {
|
|
6
|
+
canonicalPrefixWithIdEquals: string;
|
|
7
|
+
proxyPrefixWithIdEquals: string;
|
|
8
|
+
}): string;
|
|
9
|
+
declare function rewriteMailooPublicImageUrlsAnyHost(content: string, proxyPrefixWithIdEquals: string): string;
|
|
10
|
+
|
|
11
|
+
type MailooImageRewriteOptions = {
|
|
12
|
+
canonicalPrefixWithIdEquals: string;
|
|
13
|
+
proxyPrefixWithIdEquals: string;
|
|
14
|
+
};
|
|
15
|
+
type AuthorWithAvatar = {
|
|
16
|
+
avatar?: string | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Rewrite blog article fields that may contain canonical Mailoo embed URLs.
|
|
20
|
+
* `/api/v1/public/avatars/` URLs are left unchanged (they are already public).
|
|
21
|
+
*/
|
|
22
|
+
declare function rewriteMailooBlogMediaUrls<T extends {
|
|
23
|
+
ogImageUrl?: string | null;
|
|
24
|
+
htmlContent?: string | null;
|
|
25
|
+
content?: string | null;
|
|
26
|
+
author?: (AuthorWithAvatar & object) | null;
|
|
27
|
+
}>(post: T, opts: MailooImageRewriteOptions): T;
|
|
28
|
+
|
|
29
|
+
export { type MailooImageRewriteOptions, escapeRegExp, rewriteMailooBlogMediaUrls, rewriteMailooPublicImageUrls, rewriteMailooPublicImageUrlsAnyHost };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/rewrite.ts
|
|
2
|
+
function escapeRegExp(s) {
|
|
3
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
|
+
}
|
|
5
|
+
var MEDIA_ID_CAPTURE = "([a-z0-9]{20,40})";
|
|
6
|
+
function rewriteMailooPublicImageUrls(content, opts) {
|
|
7
|
+
const from = escapeRegExp(opts.canonicalPrefixWithIdEquals);
|
|
8
|
+
const re = new RegExp(from + MEDIA_ID_CAPTURE, "gi");
|
|
9
|
+
return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`);
|
|
10
|
+
}
|
|
11
|
+
var ANY_HOST_EMBED_PREFIX = /https?:\/\/[^/\s"'<>]+\/api\/v1\/images\/public\/content\?id=/gi;
|
|
12
|
+
function rewriteMailooPublicImageUrlsAnyHost(content, proxyPrefixWithIdEquals) {
|
|
13
|
+
return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/blog-media.ts
|
|
17
|
+
function rewriteMailooBlogMediaUrls(post, opts) {
|
|
18
|
+
const rewrite = (value) => {
|
|
19
|
+
if (typeof value !== "string" || value === "") return value;
|
|
20
|
+
return rewriteMailooPublicImageUrls(value, opts);
|
|
21
|
+
};
|
|
22
|
+
const author = post.author;
|
|
23
|
+
return {
|
|
24
|
+
...post,
|
|
25
|
+
ogImageUrl: rewrite(post.ogImageUrl),
|
|
26
|
+
htmlContent: rewrite(post.htmlContent),
|
|
27
|
+
content: rewrite(post.content),
|
|
28
|
+
...author ? {
|
|
29
|
+
author: {
|
|
30
|
+
...author,
|
|
31
|
+
avatar: rewrite(author.avatar)
|
|
32
|
+
}
|
|
33
|
+
} : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
escapeRegExp,
|
|
38
|
+
rewriteMailooBlogMediaUrls,
|
|
39
|
+
rewriteMailooPublicImageUrls,
|
|
40
|
+
rewriteMailooPublicImageUrlsAnyHost
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";AAGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;AChBO,SAAS,2BAOd,MAAS,MAAoC;AAC7C,QAAM,UAAU,CACd,UAC8B;AAC9B,QAAI,OAAO,UAAU,YAAY,UAAU,GAAI,QAAO;AACtD,WAAO,6BAA6B,OAAO,IAAI;AAAA,EACjD;AAEA,QAAM,SAAS,KAAK;AACpB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,QAAQ,KAAK,UAAU;AAAA,IACnC,aAAa,QAAQ,KAAK,WAAW;AAAA,IACrC,SAAS,QAAQ,KAAK,OAAO;AAAA,IAC7B,GAAI,SACA;AAAA,MACE,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,QAAQ,QAAQ,OAAO,MAAM;AAAA,MAC/B;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACF;","names":[]}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/routes/index.ts
|
|
21
|
+
var routes_exports = {};
|
|
22
|
+
__export(routes_exports, {
|
|
23
|
+
createImagesLibraryHandlers: () => createImagesLibraryHandlers,
|
|
24
|
+
createPublicImageContentHandler: () => createPublicImageContentHandler
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(routes_exports);
|
|
27
|
+
var import_next_core = require("@mailoo/next-core");
|
|
28
|
+
function resolvePublicImageApiBaseUrl(options) {
|
|
29
|
+
const raw = options?.getApiBaseUrl?.() ?? process.env.MAILOO_BLOG_API;
|
|
30
|
+
const trimmed = raw?.trim();
|
|
31
|
+
return trimmed ? trimmed.replace(/\/$/, "") : void 0;
|
|
32
|
+
}
|
|
33
|
+
function resolvePublicImageApiKey(options) {
|
|
34
|
+
const raw = options?.getApiKey?.() ?? process.env.MAILOO_BLOG_API_KEY;
|
|
35
|
+
const trimmed = raw?.trim();
|
|
36
|
+
return trimmed || void 0;
|
|
37
|
+
}
|
|
38
|
+
function createPublicImageContentHandler(options) {
|
|
39
|
+
const logger = options?.logger ?? import_next_core.defaultMailooLogger;
|
|
40
|
+
return async function GET(request) {
|
|
41
|
+
const id = request.nextUrl.searchParams.get("id")?.trim();
|
|
42
|
+
if (!id) {
|
|
43
|
+
return (0, import_next_core.jsonError)({ error: "id is required" }, 400);
|
|
44
|
+
}
|
|
45
|
+
const base = resolvePublicImageApiBaseUrl(options);
|
|
46
|
+
const apiKey = resolvePublicImageApiKey(options);
|
|
47
|
+
if (!base || !apiKey) {
|
|
48
|
+
logger.error(
|
|
49
|
+
"MAILOO_BLOG_API and MAILOO_BLOG_API_KEY must be set (or pass getApiBaseUrl / getApiKey)"
|
|
50
|
+
);
|
|
51
|
+
return (0, import_next_core.jsonError)({ error: "Image API not configured" }, 503);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const url = `${base}/api/v1/images/public/content?id=${encodeURIComponent(id)}`;
|
|
55
|
+
const response = await fetch(url, {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: { "X-API-Key": apiKey }
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const text = await response.text();
|
|
61
|
+
return new Response(text, {
|
|
62
|
+
status: response.status,
|
|
63
|
+
headers: { "Content-Type": "application/json" }
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const contentType = response.headers.get("Content-Type") ?? "application/octet-stream";
|
|
67
|
+
const cacheControl = response.headers.get("Cache-Control") ?? "public, max-age=3600";
|
|
68
|
+
return new Response(response.body, {
|
|
69
|
+
status: 200,
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": contentType,
|
|
72
|
+
"Cache-Control": cacheControl
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.logException?.(error, "Public image proxy error");
|
|
77
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createImagesLibraryHandlers(auth, options) {
|
|
82
|
+
const logger = options?.logger ?? import_next_core.defaultMailooLogger;
|
|
83
|
+
async function listOrUpload(request) {
|
|
84
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
85
|
+
if (request.method === "GET") {
|
|
86
|
+
const url = new URL(`${baseUrl}/api/v1/images`);
|
|
87
|
+
request.nextUrl.searchParams.forEach((value, key) => {
|
|
88
|
+
url.searchParams.append(key, value);
|
|
89
|
+
});
|
|
90
|
+
const response2 = await fetch(url.toString(), {
|
|
91
|
+
method: "GET",
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
Authorization: await auth.getAuthHeader(request)
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const data2 = await response2.json().catch(() => ({}));
|
|
98
|
+
return new Response(JSON.stringify(data2), {
|
|
99
|
+
status: response2.status,
|
|
100
|
+
headers: { "Content-Type": "application/json" }
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const formData = await request.formData();
|
|
104
|
+
const response = await fetch(`${baseUrl}/api/v1/images`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: { Authorization: await auth.getAuthHeader(request) },
|
|
107
|
+
body: formData
|
|
108
|
+
});
|
|
109
|
+
const data = await response.json().catch(() => ({}));
|
|
110
|
+
return new Response(JSON.stringify(data), {
|
|
111
|
+
status: response.status,
|
|
112
|
+
headers: { "Content-Type": "application/json" }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
listOrUpload: async (request) => {
|
|
117
|
+
try {
|
|
118
|
+
return await listOrUpload(request);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.logException?.(error, "BFF images list/upload error");
|
|
121
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
patch: async (request, ctx) => {
|
|
125
|
+
const { id } = await ctx.params;
|
|
126
|
+
try {
|
|
127
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
128
|
+
const body = await request.json();
|
|
129
|
+
const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {
|
|
130
|
+
method: "PATCH",
|
|
131
|
+
headers: {
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
Authorization: await auth.getAuthHeader(request)
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(body)
|
|
136
|
+
});
|
|
137
|
+
const data = await response.json().catch(() => ({}));
|
|
138
|
+
return new Response(JSON.stringify(data), {
|
|
139
|
+
status: response.status,
|
|
140
|
+
headers: { "Content-Type": "application/json" }
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
logger.logException?.(error, "BFF images PATCH error");
|
|
144
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
delete: async (request, ctx) => {
|
|
148
|
+
const { id } = await ctx.params;
|
|
149
|
+
try {
|
|
150
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
151
|
+
const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {
|
|
152
|
+
method: "DELETE",
|
|
153
|
+
headers: {
|
|
154
|
+
"Content-Type": "application/json",
|
|
155
|
+
Authorization: await auth.getAuthHeader(request)
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
const data = await response.json().catch(() => ({}));
|
|
159
|
+
return new Response(JSON.stringify(data), {
|
|
160
|
+
status: response.status,
|
|
161
|
+
headers: { "Content-Type": "application/json" }
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
logger.logException?.(error, "BFF images DELETE error");
|
|
165
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
content: async (request, ctx) => {
|
|
169
|
+
const { id } = await ctx.params;
|
|
170
|
+
try {
|
|
171
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
172
|
+
const qs = request.nextUrl.searchParams.toString();
|
|
173
|
+
const url = `${baseUrl}/api/v1/images/${id}/content${qs ? `?${qs}` : ""}`;
|
|
174
|
+
const resolve = auth.resolveAuthHeader ?? (async (r) => auth.getAuthHeader(r));
|
|
175
|
+
const response = await fetch(url, {
|
|
176
|
+
method: "GET",
|
|
177
|
+
headers: { Authorization: await resolve(request) }
|
|
178
|
+
});
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
const text = await response.text();
|
|
181
|
+
return new Response(text, {
|
|
182
|
+
status: response.status,
|
|
183
|
+
headers: { "Content-Type": "application/json" }
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const contentType = response.headers.get("Content-Type") ?? "application/octet-stream";
|
|
187
|
+
const cacheControl = response.headers.get("Cache-Control") ?? "private, max-age=3600";
|
|
188
|
+
return new Response(response.body, {
|
|
189
|
+
status: 200,
|
|
190
|
+
headers: {
|
|
191
|
+
"Content-Type": contentType,
|
|
192
|
+
"Cache-Control": cacheControl
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
logger.logException?.(error, "BFF images content stream error");
|
|
197
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
derive: async (request) => {
|
|
201
|
+
try {
|
|
202
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
203
|
+
const body = await request.json();
|
|
204
|
+
const response = await fetch(`${baseUrl}/api/v1/images/derive`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Type": "application/json",
|
|
208
|
+
Authorization: await auth.getAuthHeader(request)
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify(body)
|
|
211
|
+
});
|
|
212
|
+
const data = await response.json().catch(() => ({}));
|
|
213
|
+
return new Response(JSON.stringify(data), {
|
|
214
|
+
status: response.status,
|
|
215
|
+
headers: { "Content-Type": "application/json" }
|
|
216
|
+
});
|
|
217
|
+
} catch (error) {
|
|
218
|
+
logger.logException?.(error, "BFF images derive error");
|
|
219
|
+
return (0, import_next_core.jsonError)({ error: "Internal server error" }, 500);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
225
|
+
0 && (module.exports = {
|
|
226
|
+
createImagesLibraryHandlers,
|
|
227
|
+
createPublicImageContentHandler
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/routes/index.ts"],"sourcesContent":["import type { NextRequest } from 'next/server'\nimport {\n defaultMailooLogger,\n jsonError,\n type MailooLogger,\n} from '@mailoo/next-core'\n\nexport type ImagesBffAuth = {\n /** API base URL (no trailing slash) */\n getApiBaseUrl: () => string\n /** Authorization header for list/upload/patch/delete */\n getAuthHeader: (request: Request) => string | Promise<string>\n /** Auth for binary content (may use session cookie) */\n resolveAuthHeader?: (request: Request) => Promise<string>\n}\n\nexport type CreatePublicImageContentHandlerOptions = {\n /** Defaults to MAILOO_BLOG_API */\n getApiBaseUrl?: () => string\n /** Defaults to MAILOO_BLOG_API_KEY */\n getApiKey?: () => string\n logger?: MailooLogger\n}\n\nfunction resolvePublicImageApiBaseUrl(\n options?: CreatePublicImageContentHandlerOptions\n): string | undefined {\n const raw = options?.getApiBaseUrl?.() ?? process.env.MAILOO_BLOG_API\n const trimmed = raw?.trim()\n return trimmed ? trimmed.replace(/\\/$/, '') : undefined\n}\n\nfunction resolvePublicImageApiKey(\n options?: CreatePublicImageContentHandlerOptions\n): string | undefined {\n const raw = options?.getApiKey?.() ?? process.env.MAILOO_BLOG_API_KEY\n const trimmed = raw?.trim()\n return trimmed || undefined\n}\n\n/**\n * Public embed proxy: GET ?id=mediaCuid with X-API-Key upstream.\n * Mount at e.g. `app/api/mailoo-image/route.ts`.\n * Defaults to MAILOO_BLOG_API / MAILOO_BLOG_API_KEY; explicit getters override.\n */\nexport function createPublicImageContentHandler(\n options?: CreatePublicImageContentHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n return async function GET(request: NextRequest): Promise<Response> {\n const id = request.nextUrl.searchParams.get('id')?.trim()\n if (!id) {\n return jsonError({ error: 'id is required' }, 400)\n }\n const base = resolvePublicImageApiBaseUrl(options)\n const apiKey = resolvePublicImageApiKey(options)\n if (!base || !apiKey) {\n logger.error(\n 'MAILOO_BLOG_API and MAILOO_BLOG_API_KEY must be set ' +\n '(or pass getApiBaseUrl / getApiKey)'\n )\n return jsonError({ error: 'Image API not configured' }, 503)\n }\n try {\n const url = `${base}/api/v1/images/public/content?id=${encodeURIComponent(id)}`\n const response = await fetch(url, {\n method: 'GET',\n headers: { 'X-API-Key': apiKey },\n })\n if (!response.ok) {\n const text = await response.text()\n return new Response(text, {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const contentType =\n response.headers.get('Content-Type') ?? 'application/octet-stream'\n const cacheControl =\n response.headers.get('Cache-Control') ?? 'public, max-age=3600'\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': contentType,\n 'Cache-Control': cacheControl,\n },\n })\n } catch (error) {\n logger.logException?.(error, 'Public image proxy error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n }\n}\n\n/** Bearer-backed library BFF handlers (dashboard pattern). */\nexport function createImagesLibraryHandlers(\n auth: ImagesBffAuth,\n options?: { logger?: MailooLogger }\n) {\n const logger = options?.logger ?? defaultMailooLogger\n\n async function listOrUpload(request: NextRequest): Promise<Response> {\n const baseUrl = auth.getApiBaseUrl()\n if (request.method === 'GET') {\n const url = new URL(`${baseUrl}/api/v1/images`)\n request.nextUrl.searchParams.forEach((value, key) => {\n url.searchParams.append(key, value)\n })\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const formData = await request.formData()\n const response = await fetch(`${baseUrl}/api/v1/images`, {\n method: 'POST',\n headers: { Authorization: await auth.getAuthHeader(request) },\n body: formData,\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n return {\n listOrUpload: async (request: NextRequest) => {\n try {\n return await listOrUpload(request)\n } catch (error) {\n logger.logException?.(error, 'BFF images list/upload error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n patch: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const body = await request.json()\n const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {\n method: 'PATCH',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n body: JSON.stringify(body),\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images PATCH error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n delete: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images DELETE error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n content: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const qs = request.nextUrl.searchParams.toString()\n const url = `${baseUrl}/api/v1/images/${id}/content${qs ? `?${qs}` : ''}`\n const resolve =\n auth.resolveAuthHeader ??\n (async (r: Request) => auth.getAuthHeader(r))\n const response = await fetch(url, {\n method: 'GET',\n headers: { Authorization: await resolve(request) },\n })\n if (!response.ok) {\n const text = await response.text()\n return new Response(text, {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const contentType =\n response.headers.get('Content-Type') ?? 'application/octet-stream'\n const cacheControl =\n response.headers.get('Cache-Control') ?? 'private, max-age=3600'\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': contentType,\n 'Cache-Control': cacheControl,\n },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images content stream error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n derive: async (request: NextRequest) => {\n try {\n const baseUrl = auth.getApiBaseUrl()\n const body = await request.json()\n const response = await fetch(`${baseUrl}/api/v1/images/derive`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n body: JSON.stringify(body),\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images derive error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AAmBP,SAAS,6BACP,SACoB;AACpB,QAAM,MAAM,SAAS,gBAAgB,KAAK,QAAQ,IAAI;AACtD,QAAM,UAAU,KAAK,KAAK;AAC1B,SAAO,UAAU,QAAQ,QAAQ,OAAO,EAAE,IAAI;AAChD;AAEA,SAAS,yBACP,SACoB;AACpB,QAAM,MAAM,SAAS,YAAY,KAAK,QAAQ,IAAI;AAClD,QAAM,UAAU,KAAK,KAAK;AAC1B,SAAO,WAAW;AACpB;AAOO,SAAS,gCACd,SACA;AACA,QAAM,SAAS,SAAS,UAAU;AAClC,SAAO,eAAe,IAAI,SAAyC;AACjE,UAAM,KAAK,QAAQ,QAAQ,aAAa,IAAI,IAAI,GAAG,KAAK;AACxD,QAAI,CAAC,IAAI;AACP,iBAAO,4BAAU,EAAE,OAAO,iBAAiB,GAAG,GAAG;AAAA,IACnD;AACA,UAAM,OAAO,6BAA6B,OAAO;AACjD,UAAM,SAAS,yBAAyB,OAAO;AAC/C,QAAI,CAAC,QAAQ,CAAC,QAAQ;AACpB,aAAO;AAAA,QACL;AAAA,MAEF;AACA,iBAAO,4BAAU,EAAE,OAA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AgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,eAAO,eAAe,OAAO,yBAAyB;AACtD,mBAAO,4BAAU,EAAE,OAAO,wBAAwB,GAAG,GAAG;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AACF;","names":["response","data"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { MailooLogger } from '@mailoo/next-core';
|
|
3
|
+
|
|
4
|
+
type ImagesBffAuth = {
|
|
5
|
+
/** API base URL (no trailing slash) */
|
|
6
|
+
getApiBaseUrl: () => string;
|
|
7
|
+
/** Authorization header for list/upload/patch/delete */
|
|
8
|
+
getAuthHeader: (request: Request) => string | Promise<string>;
|
|
9
|
+
/** Auth for binary content (may use session cookie) */
|
|
10
|
+
resolveAuthHeader?: (request: Request) => Promise<string>;
|
|
11
|
+
};
|
|
12
|
+
type CreatePublicImageContentHandlerOptions = {
|
|
13
|
+
/** Defaults to MAILOO_BLOG_API */
|
|
14
|
+
getApiBaseUrl?: () => string;
|
|
15
|
+
/** Defaults to MAILOO_BLOG_API_KEY */
|
|
16
|
+
getApiKey?: () => string;
|
|
17
|
+
logger?: MailooLogger;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Public embed proxy: GET ?id=mediaCuid with X-API-Key upstream.
|
|
21
|
+
* Mount at e.g. `app/api/mailoo-image/route.ts`.
|
|
22
|
+
* Defaults to MAILOO_BLOG_API / MAILOO_BLOG_API_KEY; explicit getters override.
|
|
23
|
+
*/
|
|
24
|
+
declare function createPublicImageContentHandler(options?: CreatePublicImageContentHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
25
|
+
/** Bearer-backed library BFF handlers (dashboard pattern). */
|
|
26
|
+
declare function createImagesLibraryHandlers(auth: ImagesBffAuth, options?: {
|
|
27
|
+
logger?: MailooLogger;
|
|
28
|
+
}): {
|
|
29
|
+
listOrUpload: (request: NextRequest) => Promise<Response>;
|
|
30
|
+
patch: (request: NextRequest, ctx: {
|
|
31
|
+
params: Promise<{
|
|
32
|
+
id: string;
|
|
33
|
+
}>;
|
|
34
|
+
}) => Promise<Response>;
|
|
35
|
+
delete: (request: NextRequest, ctx: {
|
|
36
|
+
params: Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
}>;
|
|
39
|
+
}) => Promise<Response>;
|
|
40
|
+
content: (request: NextRequest, ctx: {
|
|
41
|
+
params: Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
}>;
|
|
44
|
+
}) => Promise<Response>;
|
|
45
|
+
derive: (request: NextRequest) => Promise<Response>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type CreatePublicImageContentHandlerOptions, type ImagesBffAuth, createImagesLibraryHandlers, createPublicImageContentHandler };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { MailooLogger } from '@mailoo/next-core';
|
|
3
|
+
|
|
4
|
+
type ImagesBffAuth = {
|
|
5
|
+
/** API base URL (no trailing slash) */
|
|
6
|
+
getApiBaseUrl: () => string;
|
|
7
|
+
/** Authorization header for list/upload/patch/delete */
|
|
8
|
+
getAuthHeader: (request: Request) => string | Promise<string>;
|
|
9
|
+
/** Auth for binary content (may use session cookie) */
|
|
10
|
+
resolveAuthHeader?: (request: Request) => Promise<string>;
|
|
11
|
+
};
|
|
12
|
+
type CreatePublicImageContentHandlerOptions = {
|
|
13
|
+
/** Defaults to MAILOO_BLOG_API */
|
|
14
|
+
getApiBaseUrl?: () => string;
|
|
15
|
+
/** Defaults to MAILOO_BLOG_API_KEY */
|
|
16
|
+
getApiKey?: () => string;
|
|
17
|
+
logger?: MailooLogger;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Public embed proxy: GET ?id=mediaCuid with X-API-Key upstream.
|
|
21
|
+
* Mount at e.g. `app/api/mailoo-image/route.ts`.
|
|
22
|
+
* Defaults to MAILOO_BLOG_API / MAILOO_BLOG_API_KEY; explicit getters override.
|
|
23
|
+
*/
|
|
24
|
+
declare function createPublicImageContentHandler(options?: CreatePublicImageContentHandlerOptions): (request: NextRequest) => Promise<Response>;
|
|
25
|
+
/** Bearer-backed library BFF handlers (dashboard pattern). */
|
|
26
|
+
declare function createImagesLibraryHandlers(auth: ImagesBffAuth, options?: {
|
|
27
|
+
logger?: MailooLogger;
|
|
28
|
+
}): {
|
|
29
|
+
listOrUpload: (request: NextRequest) => Promise<Response>;
|
|
30
|
+
patch: (request: NextRequest, ctx: {
|
|
31
|
+
params: Promise<{
|
|
32
|
+
id: string;
|
|
33
|
+
}>;
|
|
34
|
+
}) => Promise<Response>;
|
|
35
|
+
delete: (request: NextRequest, ctx: {
|
|
36
|
+
params: Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
}>;
|
|
39
|
+
}) => Promise<Response>;
|
|
40
|
+
content: (request: NextRequest, ctx: {
|
|
41
|
+
params: Promise<{
|
|
42
|
+
id: string;
|
|
43
|
+
}>;
|
|
44
|
+
}) => Promise<Response>;
|
|
45
|
+
derive: (request: NextRequest) => Promise<Response>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type CreatePublicImageContentHandlerOptions, type ImagesBffAuth, createImagesLibraryHandlers, createPublicImageContentHandler };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// src/routes/index.ts
|
|
2
|
+
import {
|
|
3
|
+
defaultMailooLogger,
|
|
4
|
+
jsonError
|
|
5
|
+
} from "@mailoo/next-core";
|
|
6
|
+
function resolvePublicImageApiBaseUrl(options) {
|
|
7
|
+
const raw = options?.getApiBaseUrl?.() ?? process.env.MAILOO_BLOG_API;
|
|
8
|
+
const trimmed = raw?.trim();
|
|
9
|
+
return trimmed ? trimmed.replace(/\/$/, "") : void 0;
|
|
10
|
+
}
|
|
11
|
+
function resolvePublicImageApiKey(options) {
|
|
12
|
+
const raw = options?.getApiKey?.() ?? process.env.MAILOO_BLOG_API_KEY;
|
|
13
|
+
const trimmed = raw?.trim();
|
|
14
|
+
return trimmed || void 0;
|
|
15
|
+
}
|
|
16
|
+
function createPublicImageContentHandler(options) {
|
|
17
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
18
|
+
return async function GET(request) {
|
|
19
|
+
const id = request.nextUrl.searchParams.get("id")?.trim();
|
|
20
|
+
if (!id) {
|
|
21
|
+
return jsonError({ error: "id is required" }, 400);
|
|
22
|
+
}
|
|
23
|
+
const base = resolvePublicImageApiBaseUrl(options);
|
|
24
|
+
const apiKey = resolvePublicImageApiKey(options);
|
|
25
|
+
if (!base || !apiKey) {
|
|
26
|
+
logger.error(
|
|
27
|
+
"MAILOO_BLOG_API and MAILOO_BLOG_API_KEY must be set (or pass getApiBaseUrl / getApiKey)"
|
|
28
|
+
);
|
|
29
|
+
return jsonError({ error: "Image API not configured" }, 503);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const url = `${base}/api/v1/images/public/content?id=${encodeURIComponent(id)}`;
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
method: "GET",
|
|
35
|
+
headers: { "X-API-Key": apiKey }
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
return new Response(text, {
|
|
40
|
+
status: response.status,
|
|
41
|
+
headers: { "Content-Type": "application/json" }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const contentType = response.headers.get("Content-Type") ?? "application/octet-stream";
|
|
45
|
+
const cacheControl = response.headers.get("Cache-Control") ?? "public, max-age=3600";
|
|
46
|
+
return new Response(response.body, {
|
|
47
|
+
status: 200,
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": contentType,
|
|
50
|
+
"Cache-Control": cacheControl
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
logger.logException?.(error, "Public image proxy error");
|
|
55
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createImagesLibraryHandlers(auth, options) {
|
|
60
|
+
const logger = options?.logger ?? defaultMailooLogger;
|
|
61
|
+
async function listOrUpload(request) {
|
|
62
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
63
|
+
if (request.method === "GET") {
|
|
64
|
+
const url = new URL(`${baseUrl}/api/v1/images`);
|
|
65
|
+
request.nextUrl.searchParams.forEach((value, key) => {
|
|
66
|
+
url.searchParams.append(key, value);
|
|
67
|
+
});
|
|
68
|
+
const response2 = await fetch(url.toString(), {
|
|
69
|
+
method: "GET",
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": "application/json",
|
|
72
|
+
Authorization: await auth.getAuthHeader(request)
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const data2 = await response2.json().catch(() => ({}));
|
|
76
|
+
return new Response(JSON.stringify(data2), {
|
|
77
|
+
status: response2.status,
|
|
78
|
+
headers: { "Content-Type": "application/json" }
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const formData = await request.formData();
|
|
82
|
+
const response = await fetch(`${baseUrl}/api/v1/images`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { Authorization: await auth.getAuthHeader(request) },
|
|
85
|
+
body: formData
|
|
86
|
+
});
|
|
87
|
+
const data = await response.json().catch(() => ({}));
|
|
88
|
+
return new Response(JSON.stringify(data), {
|
|
89
|
+
status: response.status,
|
|
90
|
+
headers: { "Content-Type": "application/json" }
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
listOrUpload: async (request) => {
|
|
95
|
+
try {
|
|
96
|
+
return await listOrUpload(request);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
logger.logException?.(error, "BFF images list/upload error");
|
|
99
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
patch: async (request, ctx) => {
|
|
103
|
+
const { id } = await ctx.params;
|
|
104
|
+
try {
|
|
105
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
106
|
+
const body = await request.json();
|
|
107
|
+
const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {
|
|
108
|
+
method: "PATCH",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
Authorization: await auth.getAuthHeader(request)
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify(body)
|
|
114
|
+
});
|
|
115
|
+
const data = await response.json().catch(() => ({}));
|
|
116
|
+
return new Response(JSON.stringify(data), {
|
|
117
|
+
status: response.status,
|
|
118
|
+
headers: { "Content-Type": "application/json" }
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
logger.logException?.(error, "BFF images PATCH error");
|
|
122
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
delete: async (request, ctx) => {
|
|
126
|
+
const { id } = await ctx.params;
|
|
127
|
+
try {
|
|
128
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
129
|
+
const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {
|
|
130
|
+
method: "DELETE",
|
|
131
|
+
headers: {
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
Authorization: await auth.getAuthHeader(request)
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const data = await response.json().catch(() => ({}));
|
|
137
|
+
return new Response(JSON.stringify(data), {
|
|
138
|
+
status: response.status,
|
|
139
|
+
headers: { "Content-Type": "application/json" }
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
logger.logException?.(error, "BFF images DELETE error");
|
|
143
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
content: async (request, ctx) => {
|
|
147
|
+
const { id } = await ctx.params;
|
|
148
|
+
try {
|
|
149
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
150
|
+
const qs = request.nextUrl.searchParams.toString();
|
|
151
|
+
const url = `${baseUrl}/api/v1/images/${id}/content${qs ? `?${qs}` : ""}`;
|
|
152
|
+
const resolve = auth.resolveAuthHeader ?? (async (r) => auth.getAuthHeader(r));
|
|
153
|
+
const response = await fetch(url, {
|
|
154
|
+
method: "GET",
|
|
155
|
+
headers: { Authorization: await resolve(request) }
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
const text = await response.text();
|
|
159
|
+
return new Response(text, {
|
|
160
|
+
status: response.status,
|
|
161
|
+
headers: { "Content-Type": "application/json" }
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const contentType = response.headers.get("Content-Type") ?? "application/octet-stream";
|
|
165
|
+
const cacheControl = response.headers.get("Cache-Control") ?? "private, max-age=3600";
|
|
166
|
+
return new Response(response.body, {
|
|
167
|
+
status: 200,
|
|
168
|
+
headers: {
|
|
169
|
+
"Content-Type": contentType,
|
|
170
|
+
"Cache-Control": cacheControl
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
logger.logException?.(error, "BFF images content stream error");
|
|
175
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
derive: async (request) => {
|
|
179
|
+
try {
|
|
180
|
+
const baseUrl = auth.getApiBaseUrl();
|
|
181
|
+
const body = await request.json();
|
|
182
|
+
const response = await fetch(`${baseUrl}/api/v1/images/derive`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: {
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
Authorization: await auth.getAuthHeader(request)
|
|
187
|
+
},
|
|
188
|
+
body: JSON.stringify(body)
|
|
189
|
+
});
|
|
190
|
+
const data = await response.json().catch(() => ({}));
|
|
191
|
+
return new Response(JSON.stringify(data), {
|
|
192
|
+
status: response.status,
|
|
193
|
+
headers: { "Content-Type": "application/json" }
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
logger.logException?.(error, "BFF images derive error");
|
|
197
|
+
return jsonError({ error: "Internal server error" }, 500);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export {
|
|
203
|
+
createImagesLibraryHandlers,
|
|
204
|
+
createPublicImageContentHandler
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/routes/index.ts"],"sourcesContent":["import type { NextRequest } from 'next/server'\nimport {\n defaultMailooLogger,\n jsonError,\n type MailooLogger,\n} from '@mailoo/next-core'\n\nexport type ImagesBffAuth = {\n /** API base URL (no trailing slash) */\n getApiBaseUrl: () => string\n /** Authorization header for list/upload/patch/delete */\n getAuthHeader: (request: Request) => string | Promise<string>\n /** Auth for binary content (may use session cookie) */\n resolveAuthHeader?: (request: Request) => Promise<string>\n}\n\nexport type CreatePublicImageContentHandlerOptions = {\n /** Defaults to MAILOO_BLOG_API */\n getApiBaseUrl?: () => string\n /** Defaults to MAILOO_BLOG_API_KEY */\n getApiKey?: () => string\n logger?: MailooLogger\n}\n\nfunction resolvePublicImageApiBaseUrl(\n options?: CreatePublicImageContentHandlerOptions\n): string | undefined {\n const raw = options?.getApiBaseUrl?.() ?? process.env.MAILOO_BLOG_API\n const trimmed = raw?.trim()\n return trimmed ? trimmed.replace(/\\/$/, '') : undefined\n}\n\nfunction resolvePublicImageApiKey(\n options?: CreatePublicImageContentHandlerOptions\n): string | undefined {\n const raw = options?.getApiKey?.() ?? process.env.MAILOO_BLOG_API_KEY\n const trimmed = raw?.trim()\n return trimmed || undefined\n}\n\n/**\n * Public embed proxy: GET ?id=mediaCuid with X-API-Key upstream.\n * Mount at e.g. `app/api/mailoo-image/route.ts`.\n * Defaults to MAILOO_BLOG_API / MAILOO_BLOG_API_KEY; explicit getters override.\n */\nexport function createPublicImageContentHandler(\n options?: CreatePublicImageContentHandlerOptions\n) {\n const logger = options?.logger ?? defaultMailooLogger\n return async function GET(request: NextRequest): Promise<Response> {\n const id = request.nextUrl.searchParams.get('id')?.trim()\n if (!id) {\n return jsonError({ error: 'id is required' }, 400)\n }\n const base = resolvePublicImageApiBaseUrl(options)\n const apiKey = resolvePublicImageApiKey(options)\n if (!base || !apiKey) {\n logger.error(\n 'MAILOO_BLOG_API and MAILOO_BLOG_API_KEY must be set ' +\n '(or pass getApiBaseUrl / getApiKey)'\n )\n return jsonError({ error: 'Image API not configured' }, 503)\n }\n try {\n const url = `${base}/api/v1/images/public/content?id=${encodeURIComponent(id)}`\n const response = await fetch(url, {\n method: 'GET',\n headers: { 'X-API-Key': apiKey },\n })\n if (!response.ok) {\n const text = await response.text()\n return new Response(text, {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const contentType =\n response.headers.get('Content-Type') ?? 'application/octet-stream'\n const cacheControl =\n response.headers.get('Cache-Control') ?? 'public, max-age=3600'\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': contentType,\n 'Cache-Control': cacheControl,\n },\n })\n } catch (error) {\n logger.logException?.(error, 'Public image proxy error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n }\n}\n\n/** Bearer-backed library BFF handlers (dashboard pattern). */\nexport function createImagesLibraryHandlers(\n auth: ImagesBffAuth,\n options?: { logger?: MailooLogger }\n) {\n const logger = options?.logger ?? defaultMailooLogger\n\n async function listOrUpload(request: NextRequest): Promise<Response> {\n const baseUrl = auth.getApiBaseUrl()\n if (request.method === 'GET') {\n const url = new URL(`${baseUrl}/api/v1/images`)\n request.nextUrl.searchParams.forEach((value, key) => {\n url.searchParams.append(key, value)\n })\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const formData = await request.formData()\n const response = await fetch(`${baseUrl}/api/v1/images`, {\n method: 'POST',\n headers: { Authorization: await auth.getAuthHeader(request) },\n body: formData,\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n\n return {\n listOrUpload: async (request: NextRequest) => {\n try {\n return await listOrUpload(request)\n } catch (error) {\n logger.logException?.(error, 'BFF images list/upload error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n patch: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const body = await request.json()\n const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {\n method: 'PATCH',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n body: JSON.stringify(body),\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images PATCH error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n delete: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const response = await fetch(`${baseUrl}/api/v1/images/${id}`, {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images DELETE error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n content: async (\n request: NextRequest,\n ctx: { params: Promise<{ id: string }> }\n ) => {\n const { id } = await ctx.params\n try {\n const baseUrl = auth.getApiBaseUrl()\n const qs = request.nextUrl.searchParams.toString()\n const url = `${baseUrl}/api/v1/images/${id}/content${qs ? `?${qs}` : ''}`\n const resolve =\n auth.resolveAuthHeader ??\n (async (r: Request) => auth.getAuthHeader(r))\n const response = await fetch(url, {\n method: 'GET',\n headers: { Authorization: await resolve(request) },\n })\n if (!response.ok) {\n const text = await response.text()\n return new Response(text, {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n const contentType =\n response.headers.get('Content-Type') ?? 'application/octet-stream'\n const cacheControl =\n response.headers.get('Cache-Control') ?? 'private, max-age=3600'\n return new Response(response.body, {\n status: 200,\n headers: {\n 'Content-Type': contentType,\n 'Cache-Control': cacheControl,\n },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images content stream error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n\n derive: async (request: NextRequest) => {\n try {\n const baseUrl = auth.getApiBaseUrl()\n const body = await request.json()\n const response = await fetch(`${baseUrl}/api/v1/images/derive`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: await auth.getAuthHeader(request),\n },\n body: JSON.stringify(body),\n })\n const data = await response.json().catch(() => ({}))\n return new Response(JSON.stringify(data), {\n status: response.status,\n headers: { 'Content-Type': 'application/json' },\n })\n } catch (error) {\n logger.logException?.(error, 'BFF images derive error')\n return jsonError({ error: 'Internal server error' }, 500)\n }\n },\n }\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAmBP,SAAS,6BACP,SACoB;AACpB,QAAM,MAAM,SAAS,gBAAgB,KAAK,QAAQ,IAAI;AACtD,QAAM,UAAU,KAAK,KAAK;AAC1B,SAAO,UAAU,QAAQ,QAAQ,OAAO,EAAE,IAAI;AAChD;AAEA,SAAS,yBACP,SACoB;AACpB,QAAM,MAAM,SAAS,YAAY,KAAK,QAAQ,IAAI;AAClD,QAAM,UAAU,KAAK,KAAK;AAC1B,SAAO,WAAW;AACpB;AAOO,SAAS,gCACd,SACA;AACA,QAAM,SAAS,SAAS,UAAU;AAClC,SAAO,eAAe,IAAI,SAAyC;AACjE,UAAM,KAAK,QAAQ,QA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AAA,YAChB,eAAe,MAAM,KAAK,cAAc,OAAO;AAAA,UACjD;AAAA,UACA,MAAM,KAAK,UAAU,IAAI;AAAA,QAC3B,CAAC;AACD,cAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,eAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,UACxC,QAAQ,SAAS;AAAA,UACjB,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAChD,CAAC;AAAA,MACH,SAAS,OAAO;AACd,eAAO,eAAe,OAAO,yBAAyB;AACtD,eAAO,UAAU,EAAE,OAAO,wBAAwB,GAAG,GAAG;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AACF;","names":["response","data"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailoo/images",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.32.2",
|
|
4
|
+
"description": "Mailoo image BFF helpers and public URL rewrite for Next.js",
|
|
5
|
+
"license": "LicenseRef-Mailoo-NoModification",
|
|
6
|
+
"homepage": "https://mailoo.app/en/support/docs/integrations/nextjs-packages",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mailoo",
|
|
9
|
+
"nextjs",
|
|
10
|
+
"images"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./routes": {
|
|
26
|
+
"types": "./dist/routes/index.d.ts",
|
|
27
|
+
"import": "./dist/routes/index.js",
|
|
28
|
+
"require": "./dist/routes/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@mailoo/next-core": "^1.18.4",
|
|
38
|
+
"next": ">=16.3.4"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@mailoo/next-core": "1.32.2",
|
|
42
|
+
"@types/node": "^25.9.5",
|
|
43
|
+
"next": "^16.3.4",
|
|
44
|
+
"tsup": "^8.5.1",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=20.20.2"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"clean": "rm -rf dist .turbo",
|
|
53
|
+
"type-check": "tsc --noEmit"
|
|
54
|
+
}
|
|
6
55
|
}
|