@yimingliao/cms 0.0.18 → 0.0.20
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/dist/{types-Bhnz5Z1F.d.ts → base-DbGnfZr6.d.ts} +8 -15
- package/dist/chunk-BTRPDDZJ.js +20 -0
- package/dist/{chunk-SEX4DOKX.js → chunk-YX7IPIGU.js} +1 -46
- package/dist/chunk-ZCOYQ5BG.js +46 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/server/index.d.ts +3 -23
- package/dist/server/index.js +4 -92
- package/dist/storage/r2/index.d.ts +13 -0
- package/dist/storage/r2/index.js +77 -0
- package/dist/storage/sftp/index.d.ts +20 -0
- package/dist/storage/sftp/index.js +125 -0
- package/dist/types-0oS1A2K5.d.ts +8 -0
- package/dist/types-J25u1G6t.d.ts +17 -0
- package/package.json +23 -2
|
@@ -85,7 +85,7 @@ declare const FILE_TYPES: {
|
|
|
85
85
|
};
|
|
86
86
|
type FileType = (typeof FILE_TYPES)[keyof typeof FILE_TYPES];
|
|
87
87
|
|
|
88
|
-
interface File
|
|
88
|
+
interface File {
|
|
89
89
|
id: string;
|
|
90
90
|
key: string;
|
|
91
91
|
checksum: string;
|
|
@@ -127,10 +127,10 @@ interface Folder {
|
|
|
127
127
|
type FolderFull = Folder & {
|
|
128
128
|
parentFolder: (Folder & {
|
|
129
129
|
subFolders: Folder[];
|
|
130
|
-
files: File
|
|
130
|
+
files: File[];
|
|
131
131
|
}) | null;
|
|
132
132
|
subFolders: Folder[];
|
|
133
|
-
files: File
|
|
133
|
+
files: File[];
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
declare const POST_TYPES: {
|
|
@@ -242,7 +242,7 @@ type PostListCard = Post & {
|
|
|
242
242
|
postsInTopic: Post[];
|
|
243
243
|
children: Post[];
|
|
244
244
|
taggedPosts: Post[];
|
|
245
|
-
coverImage: File
|
|
245
|
+
coverImage: File | null;
|
|
246
246
|
translations: PostTranslation[];
|
|
247
247
|
};
|
|
248
248
|
|
|
@@ -266,7 +266,7 @@ type PostFull = Post & {
|
|
|
266
266
|
translations: PostTranslation[];
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
-
type FileFull = File
|
|
269
|
+
type FileFull = File & {
|
|
270
270
|
folder: Folder | null;
|
|
271
271
|
adminAsAvatarImage: Admin[];
|
|
272
272
|
postsAsCoverImage: Post[];
|
|
@@ -280,13 +280,13 @@ type FileFull = File$1 & {
|
|
|
280
280
|
translations: FileTranslation[];
|
|
281
281
|
};
|
|
282
282
|
|
|
283
|
-
type FileCard = File
|
|
283
|
+
type FileCard = File & {
|
|
284
284
|
translations: FileTranslation[];
|
|
285
285
|
};
|
|
286
286
|
|
|
287
287
|
type AdminFull = AdminSafe & {
|
|
288
288
|
adminRefreshTokens: AdminRefreshToken[];
|
|
289
|
-
avatarImage: (File
|
|
289
|
+
avatarImage: (File & {
|
|
290
290
|
translations: FileTranslation[];
|
|
291
291
|
}) | null;
|
|
292
292
|
posts: Post[];
|
|
@@ -337,11 +337,4 @@ interface SeoMetadata {
|
|
|
337
337
|
updatedAt: Date;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
|
|
341
|
-
id: string;
|
|
342
|
-
width: number | null;
|
|
343
|
-
height: number | null;
|
|
344
|
-
duration: number | null;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export { ADMIN_ROLES as A, type BaseTranslation as B, type DeviceInfo as D, type ExternalLink as E, type FolderFull as F, type MultiItems as M, POST_TYPES as P, type SeoMetadata as S, type TocItem as T, type Admin as a, type AdminCard as b, type AdminFull as c, type AdminRefreshToken as d, type AdminRole as e, type AdminSafe as f, type AdminTranslation as g, type Alternate as h, type BlobFile as i, FILE_TYPES as j, type Faq as k, type File$1 as l, type FileCard as m, type FileFull as n, type FileTranslation as o, type FileType as p, type Folder as q, type Post as r, type PostFull as s, type PostListCard as t, type PostTranslation as u, type PostType as v, type SingleItem as w, type Translation as x };
|
|
340
|
+
export { ADMIN_ROLES as A, type BaseTranslation as B, type DeviceInfo as D, type ExternalLink as E, type FolderFull as F, type MultiItems as M, POST_TYPES as P, type SeoMetadata as S, type TocItem as T, type Admin as a, type AdminCard as b, type AdminFull as c, type AdminRefreshToken as d, type AdminRole as e, type AdminSafe as f, type AdminTranslation as g, type Alternate as h, FILE_TYPES as i, type Faq as j, type File as k, type FileCard as l, type FileFull as m, type FileTranslation as n, type FileType as o, type Folder as p, type Post as q, type PostFull as r, type PostListCard as s, type PostTranslation as t, type PostType as u, type SingleItem as v, type Translation as w };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { mimeToExtension } from './chunk-YX7IPIGU.js';
|
|
2
|
+
import path from 'path/posix';
|
|
3
|
+
import { ulid } from 'ulid';
|
|
4
|
+
|
|
5
|
+
function createObjectKey({
|
|
6
|
+
filename,
|
|
7
|
+
mimeType,
|
|
8
|
+
folderKey = ""
|
|
9
|
+
}) {
|
|
10
|
+
const extensionFromFilename = path.extname(filename ?? "").toLowerCase();
|
|
11
|
+
const extensionFromMime = !extensionFromFilename && mimeType ? `.${mimeToExtension(mimeType)}` : "";
|
|
12
|
+
const extension = extensionFromFilename || extensionFromMime;
|
|
13
|
+
const normalizedFolder = folderKey.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
14
|
+
const id = ulid();
|
|
15
|
+
const filenameWithId = id + extension;
|
|
16
|
+
if (!normalizedFolder) return filenameWithId;
|
|
17
|
+
return path.join(normalizedFolder, filenameWithId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { createObjectKey };
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { extension, lookup } from 'mime-types';
|
|
2
2
|
|
|
3
|
-
// src/domain/resources/admin/props.ts
|
|
4
|
-
var ADMIN_ROLES = {
|
|
5
|
-
SUPER_ADMIN: "SUPER_ADMIN",
|
|
6
|
-
ADMIN: "ADMIN",
|
|
7
|
-
EDITOR: "EDITOR"
|
|
8
|
-
};
|
|
9
|
-
|
|
10
3
|
// src/domain/resources/file/props.ts
|
|
11
4
|
var FILE_TYPES = {
|
|
12
5
|
IMAGE: "IMAGE",
|
|
@@ -16,44 +9,6 @@ var FILE_TYPES = {
|
|
|
16
9
|
ARCHIVE: "ARCHIVE",
|
|
17
10
|
OTHER: "OTHER"
|
|
18
11
|
};
|
|
19
|
-
|
|
20
|
-
// src/domain/resources/post/props.ts
|
|
21
|
-
var POST_TYPES = {
|
|
22
|
-
TOPIC: "TOPIC",
|
|
23
|
-
CATEGORY: "CATEGORY",
|
|
24
|
-
POST: "POST",
|
|
25
|
-
TAG: "TAG",
|
|
26
|
-
PAGE: "PAGE"
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/domain/resources/constants.ts
|
|
30
|
-
var ROOT_FOLDER_ID = "01ARZ3NDEKTSV4RRFFQ69G5FAV";
|
|
31
|
-
var ROOT_FOLDER_NAME = "ROOT";
|
|
32
|
-
var ROOT_FOLDER = {
|
|
33
|
-
id: ROOT_FOLDER_ID,
|
|
34
|
-
// core
|
|
35
|
-
name: ROOT_FOLDER_NAME,
|
|
36
|
-
key: "",
|
|
37
|
-
// states
|
|
38
|
-
isLocked: true,
|
|
39
|
-
// ---------------------------
|
|
40
|
-
// relations: Folder
|
|
41
|
-
// ---------------------------
|
|
42
|
-
parentFolder: null,
|
|
43
|
-
parentFolderId: null,
|
|
44
|
-
subFolders: [],
|
|
45
|
-
// ---------------------------
|
|
46
|
-
// relations: Folder
|
|
47
|
-
// ---------------------------
|
|
48
|
-
files: [],
|
|
49
|
-
// ---------------------------
|
|
50
|
-
// timestamps
|
|
51
|
-
// ---------------------------
|
|
52
|
-
createdAt: "",
|
|
53
|
-
updatedAt: ""
|
|
54
|
-
};
|
|
55
|
-
var SIMPLE_UPLOAD_FOLDER_NAME = "simple-upload";
|
|
56
|
-
var SIMPLE_UPLOAD_FOLDER_KEY = `${SIMPLE_UPLOAD_FOLDER_NAME}`;
|
|
57
12
|
var mimeToExtension = (mimeType) => {
|
|
58
13
|
if (!mimeType) return "unknown";
|
|
59
14
|
return (extension(mimeType) || "unknown").toLowerCase();
|
|
@@ -230,4 +185,4 @@ var result = {
|
|
|
230
185
|
error
|
|
231
186
|
};
|
|
232
187
|
|
|
233
|
-
export {
|
|
188
|
+
export { FILE_TYPES, classifyFileType, formatFileSize, getMediaInfo, mimeToExtension, result };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/domain/resources/admin/props.ts
|
|
2
|
+
var ADMIN_ROLES = {
|
|
3
|
+
SUPER_ADMIN: "SUPER_ADMIN",
|
|
4
|
+
ADMIN: "ADMIN",
|
|
5
|
+
EDITOR: "EDITOR"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/domain/resources/post/props.ts
|
|
9
|
+
var POST_TYPES = {
|
|
10
|
+
TOPIC: "TOPIC",
|
|
11
|
+
CATEGORY: "CATEGORY",
|
|
12
|
+
POST: "POST",
|
|
13
|
+
TAG: "TAG",
|
|
14
|
+
PAGE: "PAGE"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/domain/resources/constants.ts
|
|
18
|
+
var ROOT_FOLDER_ID = "01ARZ3NDEKTSV4RRFFQ69G5FAV";
|
|
19
|
+
var ROOT_FOLDER_NAME = "ROOT";
|
|
20
|
+
var ROOT_FOLDER = {
|
|
21
|
+
id: ROOT_FOLDER_ID,
|
|
22
|
+
// core
|
|
23
|
+
name: ROOT_FOLDER_NAME,
|
|
24
|
+
key: "",
|
|
25
|
+
// states
|
|
26
|
+
isLocked: true,
|
|
27
|
+
// ---------------------------
|
|
28
|
+
// relations: Folder
|
|
29
|
+
// ---------------------------
|
|
30
|
+
parentFolder: null,
|
|
31
|
+
parentFolderId: null,
|
|
32
|
+
subFolders: [],
|
|
33
|
+
// ---------------------------
|
|
34
|
+
// relations: Folder
|
|
35
|
+
// ---------------------------
|
|
36
|
+
files: [],
|
|
37
|
+
// ---------------------------
|
|
38
|
+
// timestamps
|
|
39
|
+
// ---------------------------
|
|
40
|
+
createdAt: "",
|
|
41
|
+
updatedAt: ""
|
|
42
|
+
};
|
|
43
|
+
var SIMPLE_UPLOAD_FOLDER_NAME = "simple-upload";
|
|
44
|
+
var SIMPLE_UPLOAD_FOLDER_KEY = `${SIMPLE_UPLOAD_FOLDER_NAME}`;
|
|
45
|
+
|
|
46
|
+
export { ADMIN_ROLES, POST_TYPES, ROOT_FOLDER, ROOT_FOLDER_ID, ROOT_FOLDER_NAME, SIMPLE_UPLOAD_FOLDER_KEY, SIMPLE_UPLOAD_FOLDER_NAME };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { F as FolderFull } from './
|
|
2
|
-
export { A as ADMIN_ROLES, a as Admin, b as AdminCard, c as AdminFull, d as AdminRefreshToken, e as AdminRole, f as AdminSafe, g as AdminTranslation, h as Alternate, B as BaseTranslation,
|
|
1
|
+
import { F as FolderFull } from './base-DbGnfZr6.js';
|
|
2
|
+
export { A as ADMIN_ROLES, a as Admin, b as AdminCard, c as AdminFull, d as AdminRefreshToken, e as AdminRole, f as AdminSafe, g as AdminTranslation, h as Alternate, B as BaseTranslation, D as DeviceInfo, E as ExternalLink, i as FILE_TYPES, j as Faq, k as File, l as FileCard, m as FileFull, n as FileTranslation, o as FileType, p as Folder, M as MultiItems, P as POST_TYPES, q as Post, r as PostFull, s as PostListCard, t as PostTranslation, u as PostType, S as SeoMetadata, v as SingleItem, T as TocItem, w as Translation } from './base-DbGnfZr6.js';
|
|
3
|
+
export { B as BlobFile } from './types-0oS1A2K5.js';
|
|
3
4
|
|
|
4
5
|
declare const ROOT_FOLDER_ID = "01ARZ3NDEKTSV4RRFFQ69G5FAV";
|
|
5
6
|
declare const ROOT_FOLDER_NAME = "ROOT";
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { ADMIN_ROLES,
|
|
1
|
+
export { ADMIN_ROLES, POST_TYPES, ROOT_FOLDER, ROOT_FOLDER_ID, ROOT_FOLDER_NAME, SIMPLE_UPLOAD_FOLDER_KEY, SIMPLE_UPLOAD_FOLDER_NAME } from './chunk-ZCOYQ5BG.js';
|
|
2
|
+
export { FILE_TYPES, classifyFileType, formatFileSize, getMediaInfo, mimeToExtension, result } from './chunk-YX7IPIGU.js';
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
import { BinaryLike } from 'node:crypto';
|
|
3
3
|
import { cookies } from 'next/headers';
|
|
4
|
-
import { S3Client } from '@aws-sdk/client-s3';
|
|
5
|
-
import { Logger } from 'logry';
|
|
6
|
-
import { i as BlobFile, e as AdminRole, w as SingleItem, B as BaseTranslation, a as Admin, c as AdminFull, f as AdminSafe, D as DeviceInfo, d as AdminRefreshToken, l as File, n as FileFull, p as FileType, q as Folder, F as FolderFull, v as PostType, M as MultiItems, E as ExternalLink, k as Faq, T as TocItem, r as Post, t as PostListCard, u as PostTranslation, s as PostFull, S as SeoMetadata, g as AdminTranslation, o as FileTranslation, h as Alternate } from '../types-Bhnz5Z1F.js';
|
|
7
4
|
import Keyv from 'keyv';
|
|
5
|
+
import { Logger } from 'logry';
|
|
6
|
+
import { e as AdminRole, v as SingleItem, B as BaseTranslation, a as Admin, c as AdminFull, f as AdminSafe, D as DeviceInfo, d as AdminRefreshToken, k as File, m as FileFull, o as FileType, p as Folder, F as FolderFull, u as PostType, M as MultiItems, E as ExternalLink, j as Faq, T as TocItem, q as Post, s as PostListCard, t as PostTranslation, r as PostFull, S as SeoMetadata, g as AdminTranslation, n as FileTranslation, h as Alternate } from '../base-DbGnfZr6.js';
|
|
8
7
|
|
|
9
8
|
interface CreateJwtServiceOptions {
|
|
10
9
|
defaultSecret: string;
|
|
@@ -72,25 +71,6 @@ declare function createCookieService(nextCookies: () => Promise<Awaited<ReturnTy
|
|
|
72
71
|
}) => Promise<void>;
|
|
73
72
|
};
|
|
74
73
|
|
|
75
|
-
interface CreateR2ServiceOptions {
|
|
76
|
-
r2Client: S3Client;
|
|
77
|
-
bucketName: string;
|
|
78
|
-
logger: Logger;
|
|
79
|
-
}
|
|
80
|
-
declare function createR2Service({ r2Client, bucketName, logger, }: CreateR2ServiceOptions): {
|
|
81
|
-
upload: ({ blobFile, folderKey, }: {
|
|
82
|
-
blobFile: BlobFile;
|
|
83
|
-
folderKey?: string;
|
|
84
|
-
}) => Promise<string>;
|
|
85
|
-
remove: ({ key }: {
|
|
86
|
-
key: string;
|
|
87
|
-
}) => Promise<void>;
|
|
88
|
-
move: ({ fromKey, toKey }: {
|
|
89
|
-
fromKey: string;
|
|
90
|
-
toKey: string;
|
|
91
|
-
}) => Promise<void>;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
74
|
interface CreateServerCacheOptions {
|
|
95
75
|
redisUrl: string;
|
|
96
76
|
namespace: string;
|
|
@@ -616,4 +596,4 @@ declare const POST_ORDER_BY: ({
|
|
|
616
596
|
index: "asc";
|
|
617
597
|
})[];
|
|
618
598
|
|
|
619
|
-
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, type RawCacheKey, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createCache, createCacheResult, createCookieService, createCryptoService, createFileCommandRepository, createFileQueryRepository, createFolderCommandRepository, createFolderQueryRepository, createIpRateLimiter, createJwtService, createPostCommandRepository, createPostQueryRepository,
|
|
599
|
+
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, type RawCacheKey, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createCache, createCacheResult, createCookieService, createCryptoService, createFileCommandRepository, createFileQueryRepository, createFolderCommandRepository, createFolderQueryRepository, createIpRateLimiter, createJwtService, createPostCommandRepository, createPostQueryRepository, createSeoMetadataCommandRepository, normalizeCacheKey };
|
package/dist/server/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { ADMIN_ROLES,
|
|
1
|
+
import { ADMIN_ROLES, ROOT_FOLDER_ID } from '../chunk-ZCOYQ5BG.js';
|
|
2
|
+
import { mimeToExtension, classifyFileType } from '../chunk-YX7IPIGU.js';
|
|
2
3
|
import jwt from 'jsonwebtoken';
|
|
3
4
|
import argon2 from 'argon2';
|
|
4
5
|
import crypto, { timingSafeEqual } from 'crypto';
|
|
5
6
|
import { headers } from 'next/headers';
|
|
6
|
-
import { PutObjectCommand, DeleteObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
|
|
7
|
-
import path from 'path/posix';
|
|
8
|
-
import { ulid } from 'ulid';
|
|
9
7
|
import KeyvRedis from '@keyv/redis';
|
|
10
8
|
import Keyv from 'keyv';
|
|
9
|
+
import { ulid } from 'ulid';
|
|
11
10
|
|
|
12
11
|
function createJwtService({
|
|
13
12
|
defaultSecret,
|
|
@@ -200,93 +199,6 @@ function createCookieService(nextCookies, cryptoService) {
|
|
|
200
199
|
delete: deleteCokkie
|
|
201
200
|
};
|
|
202
201
|
}
|
|
203
|
-
function createObjectKey({
|
|
204
|
-
filename,
|
|
205
|
-
mimeType,
|
|
206
|
-
folderKey = ""
|
|
207
|
-
}) {
|
|
208
|
-
const extensionFromFilename = path.extname(filename ?? "").toLowerCase();
|
|
209
|
-
const extensionFromMime = !extensionFromFilename && mimeType ? `.${mimeToExtension(mimeType)}` : "";
|
|
210
|
-
const extension = extensionFromFilename || extensionFromMime;
|
|
211
|
-
const normalizedFolder = folderKey.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
212
|
-
const id = ulid();
|
|
213
|
-
const filenameWithId = id + extension;
|
|
214
|
-
if (!normalizedFolder) return filenameWithId;
|
|
215
|
-
return path.join(normalizedFolder, filenameWithId);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/server/infrastructure/r2/r2.service.ts
|
|
219
|
-
function createR2Service({
|
|
220
|
-
r2Client,
|
|
221
|
-
bucketName,
|
|
222
|
-
logger
|
|
223
|
-
}) {
|
|
224
|
-
async function upload({
|
|
225
|
-
blobFile,
|
|
226
|
-
folderKey = ""
|
|
227
|
-
}) {
|
|
228
|
-
const key = createObjectKey({
|
|
229
|
-
filename: blobFile.name,
|
|
230
|
-
mimeType: blobFile.type,
|
|
231
|
-
folderKey
|
|
232
|
-
});
|
|
233
|
-
try {
|
|
234
|
-
const buffer = Buffer.from(await blobFile.arrayBuffer());
|
|
235
|
-
await r2Client.send(
|
|
236
|
-
new PutObjectCommand({
|
|
237
|
-
Bucket: bucketName,
|
|
238
|
-
Key: key,
|
|
239
|
-
Body: buffer,
|
|
240
|
-
ContentType: blobFile.type || void 0
|
|
241
|
-
})
|
|
242
|
-
);
|
|
243
|
-
logger.debug("R2 upload success", { key });
|
|
244
|
-
return key;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
logger.error("upload failed", { key, error });
|
|
247
|
-
throw error;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
async function remove({ key }) {
|
|
251
|
-
try {
|
|
252
|
-
await r2Client.send(
|
|
253
|
-
new DeleteObjectCommand({
|
|
254
|
-
Bucket: bucketName,
|
|
255
|
-
Key: key
|
|
256
|
-
})
|
|
257
|
-
);
|
|
258
|
-
logger.debug("R2 object removed", { key });
|
|
259
|
-
} catch (error) {
|
|
260
|
-
logger.error("Remove failed", { key, error });
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function move({ fromKey, toKey }) {
|
|
265
|
-
if (fromKey === toKey) {
|
|
266
|
-
logger.debug("R2 move skipped (same key)", { key: fromKey });
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
try {
|
|
270
|
-
await r2Client.send(
|
|
271
|
-
new CopyObjectCommand({
|
|
272
|
-
Bucket: bucketName,
|
|
273
|
-
CopySource: encodeURI(`${bucketName}/${fromKey}`),
|
|
274
|
-
Key: toKey
|
|
275
|
-
})
|
|
276
|
-
);
|
|
277
|
-
await remove({ key: fromKey });
|
|
278
|
-
logger.debug("R2 object moved", { fromKey, toKey });
|
|
279
|
-
} catch (error) {
|
|
280
|
-
logger.error("Move failed", { fromKey, toKey, error });
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
upload,
|
|
286
|
-
remove,
|
|
287
|
-
move
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
202
|
|
|
291
203
|
// src/server/infrastructure/cache/cache-key-delimiter.ts
|
|
292
204
|
var CACHE_KEY_DELIMITER = "|";
|
|
@@ -1509,4 +1421,4 @@ function createSeoMetadataCommandRepository(prisma) {
|
|
|
1509
1421
|
};
|
|
1510
1422
|
}
|
|
1511
1423
|
|
|
1512
|
-
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createCache, createCacheResult, createCookieService, createCryptoService, createFileCommandRepository, createFileQueryRepository, createFolderCommandRepository, createFolderQueryRepository, createIpRateLimiter, createJwtService, createPostCommandRepository, createPostQueryRepository,
|
|
1424
|
+
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createCache, createCacheResult, createCookieService, createCryptoService, createFileCommandRepository, createFileQueryRepository, createFolderCommandRepository, createFolderQueryRepository, createIpRateLimiter, createJwtService, createPostCommandRepository, createPostQueryRepository, createSeoMetadataCommandRepository, normalizeCacheKey };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import { Logger } from 'logry';
|
|
3
|
+
import { S as StorageService } from '../../types-J25u1G6t.js';
|
|
4
|
+
import '../../types-0oS1A2K5.js';
|
|
5
|
+
|
|
6
|
+
interface CreateR2ServiceOptions {
|
|
7
|
+
r2Client: S3Client;
|
|
8
|
+
bucketName: string;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}
|
|
11
|
+
declare function createR2Service({ r2Client, bucketName, logger, }: CreateR2ServiceOptions): StorageService;
|
|
12
|
+
|
|
13
|
+
export { createR2Service };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createObjectKey } from '../../chunk-BTRPDDZJ.js';
|
|
2
|
+
import '../../chunk-YX7IPIGU.js';
|
|
3
|
+
import { PutObjectCommand, DeleteObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
|
|
4
|
+
|
|
5
|
+
function createR2Service({
|
|
6
|
+
r2Client,
|
|
7
|
+
bucketName,
|
|
8
|
+
logger
|
|
9
|
+
}) {
|
|
10
|
+
async function upload({
|
|
11
|
+
blobFile,
|
|
12
|
+
folderKey = ""
|
|
13
|
+
}) {
|
|
14
|
+
const key = createObjectKey({
|
|
15
|
+
filename: blobFile.name,
|
|
16
|
+
mimeType: blobFile.type,
|
|
17
|
+
folderKey
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
const buffer = Buffer.from(await blobFile.arrayBuffer());
|
|
21
|
+
await r2Client.send(
|
|
22
|
+
new PutObjectCommand({
|
|
23
|
+
Bucket: bucketName,
|
|
24
|
+
Key: key,
|
|
25
|
+
Body: buffer,
|
|
26
|
+
ContentType: blobFile.type || void 0
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
logger.debug("R2 upload success", { key });
|
|
30
|
+
return key;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logger.error("R2 upload failed", { key, error });
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function remove({ key }) {
|
|
37
|
+
try {
|
|
38
|
+
await r2Client.send(
|
|
39
|
+
new DeleteObjectCommand({
|
|
40
|
+
Bucket: bucketName,
|
|
41
|
+
Key: key
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
logger.debug("R2 object removed", { key });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error("R2 remove failed", { key, error });
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function move({ fromKey, toKey }) {
|
|
51
|
+
if (fromKey === toKey) {
|
|
52
|
+
logger.debug("R2 move skipped (same key)", { key: fromKey });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await r2Client.send(
|
|
57
|
+
new CopyObjectCommand({
|
|
58
|
+
Bucket: bucketName,
|
|
59
|
+
CopySource: encodeURI(`${bucketName}/${fromKey}`),
|
|
60
|
+
Key: toKey
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
await remove({ key: fromKey });
|
|
64
|
+
logger.debug("R2 object moved", { fromKey, toKey });
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logger.error("R2 move failed", { fromKey, toKey, error });
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
upload,
|
|
72
|
+
remove,
|
|
73
|
+
move
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { createR2Service };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Logger } from 'logry';
|
|
2
|
+
import { Pool } from 'generic-pool';
|
|
3
|
+
import SFTPClient from 'ssh2-sftp-client';
|
|
4
|
+
import { S as StorageService } from '../../types-J25u1G6t.js';
|
|
5
|
+
import '../../types-0oS1A2K5.js';
|
|
6
|
+
|
|
7
|
+
interface CreateSftpServiceOptions {
|
|
8
|
+
sftpPool: Pool<SFTPClient>;
|
|
9
|
+
basePath: string;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
}
|
|
12
|
+
declare function createSftpService({ sftpPool, basePath, logger, }: CreateSftpServiceOptions): StorageService;
|
|
13
|
+
|
|
14
|
+
interface CreateSftpPoolOptions {
|
|
15
|
+
sftpClientOptions: SFTPClient.ConnectOptions;
|
|
16
|
+
logger: Logger;
|
|
17
|
+
}
|
|
18
|
+
declare const createSftpPool: ({ sftpClientOptions, logger, }: CreateSftpPoolOptions) => Pool<SFTPClient>;
|
|
19
|
+
|
|
20
|
+
export { createSftpPool, createSftpService };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createObjectKey } from '../../chunk-BTRPDDZJ.js';
|
|
2
|
+
import '../../chunk-YX7IPIGU.js';
|
|
3
|
+
import path from 'path/posix';
|
|
4
|
+
import { createPool } from 'generic-pool';
|
|
5
|
+
import SFTPClient from 'ssh2-sftp-client';
|
|
6
|
+
|
|
7
|
+
function createSftpService({
|
|
8
|
+
sftpPool,
|
|
9
|
+
basePath,
|
|
10
|
+
logger
|
|
11
|
+
}) {
|
|
12
|
+
async function upload({
|
|
13
|
+
blobFile,
|
|
14
|
+
folderKey = ""
|
|
15
|
+
}) {
|
|
16
|
+
const key = createObjectKey({
|
|
17
|
+
filename: blobFile.name,
|
|
18
|
+
mimeType: blobFile.type,
|
|
19
|
+
folderKey
|
|
20
|
+
});
|
|
21
|
+
const fullPath = path.join(basePath, key);
|
|
22
|
+
const client = await sftpPool.acquire();
|
|
23
|
+
try {
|
|
24
|
+
const buffer = Buffer.from(await blobFile.arrayBuffer());
|
|
25
|
+
await client.put(buffer, fullPath);
|
|
26
|
+
logger.debug("SFTP upload success", { key });
|
|
27
|
+
return key;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
logger.error("SFTP upload failed", { key, error });
|
|
30
|
+
throw error;
|
|
31
|
+
} finally {
|
|
32
|
+
await sftpPool.release(client);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function remove({ key }) {
|
|
36
|
+
const fullPath = path.join(basePath, key);
|
|
37
|
+
const client = await sftpPool.acquire();
|
|
38
|
+
try {
|
|
39
|
+
await client.delete(fullPath);
|
|
40
|
+
logger.debug("SFTP object removed", { key });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof Error && /no such file/i.test(error.message)) {
|
|
43
|
+
logger.debug("SFTP remove skipped (not found)", { key });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
logger.error("SFTP remove failed", { key, error });
|
|
47
|
+
throw error;
|
|
48
|
+
} finally {
|
|
49
|
+
await sftpPool.release(client);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function move({ fromKey, toKey }) {
|
|
53
|
+
if (fromKey === toKey) {
|
|
54
|
+
logger.debug("SFTP move skipped (same key)", { key: fromKey });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const fromPath = path.join(basePath, fromKey);
|
|
58
|
+
const toPath = path.join(basePath, toKey);
|
|
59
|
+
const client = await sftpPool.acquire();
|
|
60
|
+
try {
|
|
61
|
+
await client.rename(fromPath, toPath);
|
|
62
|
+
logger.debug("SFTP object moved", { fromKey, toKey });
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.error("SFTP move failed", { fromKey, toKey, error });
|
|
65
|
+
throw error;
|
|
66
|
+
} finally {
|
|
67
|
+
await sftpPool.release(client);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
upload,
|
|
72
|
+
remove,
|
|
73
|
+
move
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var createSftpPool = ({
|
|
77
|
+
sftpClientOptions,
|
|
78
|
+
logger
|
|
79
|
+
}) => {
|
|
80
|
+
return createPool(
|
|
81
|
+
{
|
|
82
|
+
create: async () => {
|
|
83
|
+
const client = new SFTPClient();
|
|
84
|
+
try {
|
|
85
|
+
await client.connect({
|
|
86
|
+
readyTimeout: 2e4,
|
|
87
|
+
keepaliveInterval: 1e4,
|
|
88
|
+
keepaliveCountMax: 3,
|
|
89
|
+
...sftpClientOptions
|
|
90
|
+
});
|
|
91
|
+
return client;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
logger.error("SFTP connect failed", { error });
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
validate: async (client) => {
|
|
98
|
+
try {
|
|
99
|
+
await client.realPath("/");
|
|
100
|
+
return true;
|
|
101
|
+
} catch {
|
|
102
|
+
logger.debug("SFTP session invalid, removing from pool");
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
destroy: async (client) => {
|
|
107
|
+
try {
|
|
108
|
+
await client.end();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
logger.error("SFTP destroy failed", { error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
max: 3,
|
|
116
|
+
min: 0,
|
|
117
|
+
idleTimeoutMillis: 6e4,
|
|
118
|
+
acquireTimeoutMillis: 1e4,
|
|
119
|
+
evictionRunIntervalMillis: 3e4,
|
|
120
|
+
testOnBorrow: true
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { createSftpPool, createSftpService };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { B as BlobFile } from './types-0oS1A2K5.js';
|
|
2
|
+
|
|
3
|
+
interface StorageService {
|
|
4
|
+
upload(options: {
|
|
5
|
+
blobFile: BlobFile;
|
|
6
|
+
folderKey?: string;
|
|
7
|
+
}): Promise<string>;
|
|
8
|
+
remove(options: {
|
|
9
|
+
key: string;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
move(options: {
|
|
12
|
+
fromKey: string;
|
|
13
|
+
toKey: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { StorageService as S };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yimingliao/cms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"author": "Yiming Liao",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
"types": "./dist/server/index.d.ts",
|
|
15
15
|
"import": "./dist/server/index.js",
|
|
16
16
|
"require": "./dist/server/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./storage/r2": {
|
|
19
|
+
"types": "./dist/storage/r2/index.d.ts",
|
|
20
|
+
"import": "./dist/storage/r2/index.js",
|
|
21
|
+
"require": "./dist/storage/r2/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./storage/sftp": {
|
|
24
|
+
"types": "./dist/storage/sftp/index.d.ts",
|
|
25
|
+
"import": "./dist/storage/sftp/index.js",
|
|
26
|
+
"require": "./dist/storage/sftp/index.js"
|
|
17
27
|
}
|
|
18
28
|
},
|
|
19
29
|
"files": [
|
|
@@ -35,20 +45,31 @@
|
|
|
35
45
|
"ulid": "^3.0.2"
|
|
36
46
|
},
|
|
37
47
|
"devDependencies": {
|
|
48
|
+
"@aws-sdk/client-s3": "^3.1004.0",
|
|
38
49
|
"@prisma/client": "6.5.0",
|
|
39
50
|
"@types/jsonwebtoken": "^9.0.10",
|
|
40
51
|
"@types/mime-types": "^3.0.1",
|
|
52
|
+
"@types/ssh2-sftp-client": "^9.0.6",
|
|
53
|
+
"generic-pool": "^3.9.0",
|
|
41
54
|
"next": "^16.1.6",
|
|
42
55
|
"prisma": "6.5.0",
|
|
43
56
|
"tsup": "^8.5.1",
|
|
44
57
|
"typescript": "^5.9.3"
|
|
45
58
|
},
|
|
46
59
|
"peerDependencies": {
|
|
47
|
-
"@aws-sdk/client-s3": "^3.0.0"
|
|
60
|
+
"@aws-sdk/client-s3": "^3.0.0",
|
|
61
|
+
"generic-pool": "^3.9.0",
|
|
62
|
+
"ssh2-sftp-client": "^12.1.0"
|
|
48
63
|
},
|
|
49
64
|
"peerDependenciesMeta": {
|
|
50
65
|
"@aws-sdk/client-s3": {
|
|
51
66
|
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"generic-pool": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"ssh2-sftp-client": {
|
|
72
|
+
"optional": true
|
|
52
73
|
}
|
|
53
74
|
}
|
|
54
75
|
}
|