@s-hirano-ist/s-scripts 4.1.0 → 4.2.0

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.
@@ -2,7 +2,7 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
2
2
  import {
3
3
  makeExportedAt,
4
4
  withTransactionRetry
5
- } from "./chunk-DIG75T3J.js";
5
+ } from "./chunk-RLAYINCA.js";
6
6
 
7
7
  // ../application/dist/batch/books-batch-service.js
8
8
  var BooksBatchApplicationService = class {
@@ -2,7 +2,7 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
2
2
  import {
3
3
  makeExportedAt,
4
4
  withTransactionRetry
5
- } from "./chunk-DIG75T3J.js";
5
+ } from "./chunk-RLAYINCA.js";
6
6
 
7
7
  // ../application/dist/batch/images-batch-service.js
8
8
  var ImagesBatchApplicationService = class {
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- createMinioClient
5
- } from "./chunk-F4J6JBR4.js";
4
+ createObjectStorageClient
5
+ } from "./chunk-M6LFKOUH.js";
6
6
  import {
7
7
  createPushoverService
8
8
  } from "./chunk-7PVU2Z32.js";
@@ -21,15 +21,7 @@ function isImageFile(filePath) {
21
21
  return [".jpg", ".jpeg", ".png", ".webp"].includes(ext);
22
22
  }
23
23
  function listObjects(client, bucket, prefix) {
24
- const { promise, resolve, reject } = Promise.withResolvers();
25
- const keys = [];
26
- const stream = client.listObjectsV2(bucket, prefix, true);
27
- stream.on("data", (obj) => {
28
- if (obj.name) keys.push(obj.name);
29
- });
30
- stream.on("end", () => resolve(keys));
31
- stream.on("error", reject);
32
- return promise;
24
+ return client.listObjects(bucket, prefix);
33
25
  }
34
26
  async function main() {
35
27
  const dryRun = process.argv.includes("--dry-run");
@@ -37,24 +29,19 @@ async function main() {
37
29
  PUSHOVER_URL: process.env.PUSHOVER_URL,
38
30
  PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
39
31
  PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
40
- MINIO_BUCKET_NAME: process.env.MINIO_BUCKET_NAME
32
+ S3_BUCKET_NAME: process.env.S3_BUCKET_NAME
41
33
  };
42
34
  if (Object.values(env).some((v) => !v)) {
43
35
  throw new Error("Required environment variables are not set.");
44
36
  }
45
- if (process.env.MINIO_USE_SSL === "true" && (!process.env.CF_ACCESS_CLIENT_ID || !process.env.CF_ACCESS_CLIENT_SECRET)) {
46
- throw new Error(
47
- "CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET are required when MINIO_USE_SSL is true."
48
- );
49
- }
50
37
  const contentsPath = process.env.S_CONTENTS_PATH ?? process.cwd();
51
38
  const notificationService = createPushoverService({
52
39
  url: env.PUSHOVER_URL ?? "",
53
40
  userKey: env.PUSHOVER_USER_KEY ?? "",
54
41
  appToken: env.PUSHOVER_APP_TOKEN ?? ""
55
42
  });
56
- const minioClient = createMinioClient();
57
- const bucketName = env.MINIO_BUCKET_NAME ?? "";
43
+ const storageClient = createObjectStorageClient();
44
+ const bucketName = env.S3_BUCKET_NAME ?? "";
58
45
  try {
59
46
  const localFiles = await globPaths(`${contentsPath}/image/dump/*`);
60
47
  const localFileNames = new Set(
@@ -64,11 +51,11 @@ async function main() {
64
51
  `\u{1F4C1} \u30ED\u30FC\u30AB\u30EB\u306B ${localFileNames.size} \u4EF6\u306E\u753B\u50CF\u30D5\u30A1\u30A4\u30EB\u3092\u691C\u51FA\u3057\u307E\u3057\u305F\u3002`
65
52
  );
66
53
  const [originalKeys, thumbnailKeys] = await Promise.all([
67
- listObjects(minioClient, bucketName, `${ORIGINAL_IMAGE_PATH}/`),
68
- listObjects(minioClient, bucketName, `${THUMBNAIL_IMAGE_PATH}/`)
54
+ listObjects(storageClient, bucketName, `${ORIGINAL_IMAGE_PATH}/`),
55
+ listObjects(storageClient, bucketName, `${THUMBNAIL_IMAGE_PATH}/`)
69
56
  ]);
70
57
  console.log(
71
- `\u{1F4E6} MinIO: original ${originalKeys.length} \u4EF6, thumbnail ${thumbnailKeys.length} \u4EF6`
58
+ `\u{1F4E6} S3: original ${originalKeys.length} \u4EF6, thumbnail ${thumbnailKeys.length} \u4EF6`
72
59
  );
73
60
  const orphanedOriginals = originalKeys.filter(
74
61
  (key) => !localFileNames.has(basename(key))
@@ -79,10 +66,11 @@ async function main() {
79
66
  const totalOrphaned = orphanedOriginals.length + orphanedThumbnails.length;
80
67
  if (totalOrphaned === 0) {
81
68
  console.log("\u2705 \u5B64\u7ACB\u30D5\u30A1\u30A4\u30EB\u306A\u3057");
82
- await notificationService.notifyInfo(
83
- `${SCRIPT_NAME} completed: no orphaned files`,
84
- { caller: SCRIPT_NAME }
85
- );
69
+ if (!dryRun)
70
+ await notificationService.notifyInfo(
71
+ `${SCRIPT_NAME} completed: no orphaned files`,
72
+ { caller: SCRIPT_NAME }
73
+ );
86
74
  return;
87
75
  }
88
76
  console.log(
@@ -95,7 +83,7 @@ async function main() {
95
83
  if (dryRun) {
96
84
  console.log(`\u{1F50D} [dry-run] \u524A\u9664\u4E88\u5B9A: ${key}`);
97
85
  } else {
98
- await minioClient.removeObject(bucketName, key);
86
+ await storageClient.removeObject(bucketName, key);
99
87
  console.log(`\u{1F5D1}\uFE0F \u524A\u9664: ${key}`);
100
88
  }
101
89
  deletedCount++;
@@ -108,17 +96,19 @@ async function main() {
108
96
  `
109
97
  \u{1F4CA} \u7D50\u679C: \u524A\u9664 ${deletedCount} \u4EF6, \u30A8\u30E9\u30FC ${errorCount} \u4EF6${dryRun ? " (dry-run)" : ""}`
110
98
  );
111
- await notificationService.notifyInfo(`${SCRIPT_NAME} completed`, {
112
- caller: SCRIPT_NAME
113
- });
99
+ if (!dryRun)
100
+ await notificationService.notifyInfo(`${SCRIPT_NAME} completed`, {
101
+ caller: SCRIPT_NAME
102
+ });
114
103
  } catch (error) {
115
104
  console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
116
- await notificationService.notifyError(
117
- `${SCRIPT_NAME} failed: ${String(error)}`,
118
- {
119
- caller: SCRIPT_NAME
120
- }
121
- );
105
+ if (!dryRun)
106
+ await notificationService.notifyError(
107
+ `${SCRIPT_NAME} failed: ${String(error)}`,
108
+ {
109
+ caller: SCRIPT_NAME
110
+ }
111
+ );
122
112
  process.exit(1);
123
113
  }
124
114
  }
@@ -4,7 +4,7 @@ import {
4
4
  createPrismaClient,
5
5
  makeUnexportedStatus,
6
6
  makeUserId
7
- } from "./chunk-DIG75T3J.js";
7
+ } from "./chunk-RLAYINCA.js";
8
8
  import {
9
9
  createPushoverService
10
10
  } from "./chunk-7PVU2Z32.js";
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- createMinioClient
5
- } from "./chunk-F4J6JBR4.js";
4
+ createObjectStorageClient
5
+ } from "./chunk-M6LFKOUH.js";
6
6
  import {
7
7
  createPrismaClient,
8
8
  makeUnexportedStatus,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -81,23 +81,18 @@ async function main() {
81
81
  PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
82
82
  PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
83
83
  USERNAME_TO_EXPORT: process.env.USERNAME_TO_EXPORT,
84
- MINIO_BUCKET_NAME: process.env.MINIO_BUCKET_NAME
84
+ S3_BUCKET_NAME: process.env.S3_BUCKET_NAME
85
85
  };
86
86
  if (Object.values(env).some((v) => !v)) {
87
87
  throw new Error("Required environment variables are not set.");
88
88
  }
89
- if (process.env.MINIO_USE_SSL === "true" && (!process.env.CF_ACCESS_CLIENT_ID || !process.env.CF_ACCESS_CLIENT_SECRET)) {
90
- throw new Error(
91
- "CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET are required when MINIO_USE_SSL is true."
92
- );
93
- }
94
89
  const prisma = createPrismaClient(env.DATABASE_URL ?? "");
95
90
  const notificationService = createPushoverService({
96
91
  url: env.PUSHOVER_URL ?? "",
97
92
  userKey: env.PUSHOVER_USER_KEY ?? "",
98
93
  appToken: env.PUSHOVER_APP_TOKEN ?? ""
99
94
  });
100
- const minioClient = createMinioClient();
95
+ const storageClient = createObjectStorageClient();
101
96
  const userId = makeUserId(env.USERNAME_TO_EXPORT ?? "");
102
97
  const UNEXPORTED = makeUnexportedStatus();
103
98
  async function downloadBookImages(books) {
@@ -122,8 +117,8 @@ async function main() {
122
117
  } catch {
123
118
  }
124
119
  await withRetry(
125
- () => minioClient.fGetObject(
126
- env.MINIO_BUCKET_NAME ?? "",
120
+ () => storageClient.downloadObject(
121
+ env.S3_BUCKET_NAME ?? "",
127
122
  `books/original/${imagePath}`,
128
123
  filePath
129
124
  )
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- createMinioClient
5
- } from "./chunk-F4J6JBR4.js";
4
+ createObjectStorageClient
5
+ } from "./chunk-M6LFKOUH.js";
6
6
  import {
7
7
  createPrismaClient,
8
8
  makeUnexportedStatus,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -37,23 +37,18 @@ async function main() {
37
37
  PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
38
38
  PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
39
39
  USERNAME_TO_EXPORT: process.env.USERNAME_TO_EXPORT,
40
- MINIO_BUCKET_NAME: process.env.MINIO_BUCKET_NAME
40
+ S3_BUCKET_NAME: process.env.S3_BUCKET_NAME
41
41
  };
42
42
  if (Object.values(env).some((v) => !v)) {
43
43
  throw new Error("Required environment variables are not set.");
44
44
  }
45
- if (process.env.MINIO_USE_SSL === "true" && (!process.env.CF_ACCESS_CLIENT_ID || !process.env.CF_ACCESS_CLIENT_SECRET)) {
46
- throw new Error(
47
- "CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET are required when MINIO_USE_SSL is true."
48
- );
49
- }
50
45
  const prisma = createPrismaClient(env.DATABASE_URL ?? "");
51
46
  const notificationService = createPushoverService({
52
47
  url: env.PUSHOVER_URL ?? "",
53
48
  userKey: env.PUSHOVER_USER_KEY ?? "",
54
49
  appToken: env.PUSHOVER_APP_TOKEN ?? ""
55
50
  });
56
- const minioClient = createMinioClient();
51
+ const storageClient = createObjectStorageClient();
57
52
  const userId = makeUserId(env.USERNAME_TO_EXPORT ?? "");
58
53
  const UNEXPORTED = makeUnexportedStatus();
59
54
  async function fetchImages() {
@@ -68,8 +63,8 @@ async function main() {
68
63
  const filePath = path.join(outputDir, imagePath);
69
64
  await mkdir(path.dirname(filePath), { recursive: true });
70
65
  await withRetry(
71
- () => minioClient.fGetObject(
72
- env.MINIO_BUCKET_NAME ?? "",
66
+ () => storageClient.downloadObject(
67
+ env.S3_BUCKET_NAME ?? "",
73
68
  `images/original/${imagePath}`,
74
69
  filePath
75
70
  )
@@ -4,7 +4,7 @@ import {
4
4
  createPrismaClient,
5
5
  makeUnexportedStatus,
6
6
  makeUserId
7
- } from "./chunk-DIG75T3J.js";
7
+ } from "./chunk-RLAYINCA.js";
8
8
  import {
9
9
  createPushoverService
10
10
  } from "./chunk-7PVU2Z32.js";
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-IYGLKY27.js";
6
6
  import {
7
7
  runContentImport
8
- } from "./chunk-2PZXXOYG.js";
8
+ } from "./chunk-R5EI7JXR.js";
9
9
  import "./chunk-KKZP7ZF3.js";
10
- import "./chunk-F4J6JBR4.js";
11
- import "./chunk-DIG75T3J.js";
10
+ import "./chunk-M6LFKOUH.js";
11
+ import "./chunk-RLAYINCA.js";
12
12
  import "./chunk-7PVU2Z32.js";
13
13
  import {
14
14
  globPaths
@@ -3,10 +3,10 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  makeISBN,
5
5
  runContentImport
6
- } from "./chunk-2PZXXOYG.js";
6
+ } from "./chunk-R5EI7JXR.js";
7
7
  import "./chunk-KKZP7ZF3.js";
8
- import "./chunk-F4J6JBR4.js";
9
- import "./chunk-DIG75T3J.js";
8
+ import "./chunk-M6LFKOUH.js";
9
+ import "./chunk-RLAYINCA.js";
10
10
  import "./chunk-7PVU2Z32.js";
11
11
  import {
12
12
  parseMarkdownFrontmatter
@@ -3,10 +3,10 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  runContentImport,
5
5
  sharpImageProcessor
6
- } from "./chunk-2PZXXOYG.js";
6
+ } from "./chunk-R5EI7JXR.js";
7
7
  import "./chunk-KKZP7ZF3.js";
8
- import "./chunk-F4J6JBR4.js";
9
- import "./chunk-DIG75T3J.js";
8
+ import "./chunk-M6LFKOUH.js";
9
+ import "./chunk-RLAYINCA.js";
10
10
  import "./chunk-7PVU2Z32.js";
11
11
  import {
12
12
  globPaths
@@ -2,10 +2,10 @@
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
4
  runContentImport
5
- } from "./chunk-2PZXXOYG.js";
5
+ } from "./chunk-R5EI7JXR.js";
6
6
  import "./chunk-KKZP7ZF3.js";
7
- import "./chunk-F4J6JBR4.js";
8
- import "./chunk-DIG75T3J.js";
7
+ import "./chunk-M6LFKOUH.js";
8
+ import "./chunk-RLAYINCA.js";
9
9
  import "./chunk-7PVU2Z32.js";
10
10
  import {
11
11
  parseMarkdownFrontmatter
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  ArticlesBatchApplicationService,
5
5
  createArticlesCommandRepository
6
- } from "./chunk-OCEV2QX3.js";
6
+ } from "./chunk-BYEEIQ7O.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  BooksBatchApplicationService,
5
5
  createBooksCommandRepository
6
- } from "./chunk-MNBEFEFR.js";
6
+ } from "./chunk-RO5QUZFR.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  ImagesBatchApplicationService,
5
5
  createImagesCommandRepository
6
- } from "./chunk-FVK44UTM.js";
6
+ } from "./chunk-ZMQUO6OA.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  NotesBatchApplicationService,
5
5
  createNotesCommandRepository
6
- } from "./chunk-7XX57D7G.js";
6
+ } from "./chunk-3INTMHPH.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  ArticlesBatchApplicationService,
5
5
  createArticlesCommandRepository
6
- } from "./chunk-OCEV2QX3.js";
6
+ } from "./chunk-BYEEIQ7O.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  BooksBatchApplicationService,
5
5
  createBooksCommandRepository
6
- } from "./chunk-MNBEFEFR.js";
6
+ } from "./chunk-RO5QUZFR.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  ImagesBatchApplicationService,
5
5
  createImagesCommandRepository
6
- } from "./chunk-FVK44UTM.js";
6
+ } from "./chunk-ZMQUO6OA.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
@@ -3,11 +3,11 @@ import { createRequire as __cliCreateRequire } from "node:module"; const require
3
3
  import {
4
4
  NotesBatchApplicationService,
5
5
  createNotesCommandRepository
6
- } from "./chunk-7XX57D7G.js";
6
+ } from "./chunk-3INTMHPH.js";
7
7
  import {
8
8
  createPrismaClient,
9
9
  makeUserId
10
- } from "./chunk-DIG75T3J.js";
10
+ } from "./chunk-RLAYINCA.js";
11
11
  import {
12
12
  createPushoverService
13
13
  } from "./chunk-7PVU2Z32.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s-hirano-ist/s-scripts",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "CLI scripts for s-private data operations",
5
5
  "engines": {
6
6
  "node": "26.x"
@@ -49,19 +49,19 @@
49
49
  },
50
50
  "license": "AGPL-3.0",
51
51
  "dependencies": {
52
+ "@aws-sdk/client-s3": "3.1163.0",
52
53
  "@googleapis/books": "13.0.1",
53
- "@prisma/adapter-pg": "7.10.0",
54
- "@prisma/client-runtime-utils": "7.10.0",
55
- "@qdrant/js-client-rest": "1.19.0",
54
+ "@prisma/adapter-pg": "7.10.1",
55
+ "@prisma/client-runtime-utils": "7.10.1",
56
+ "@qdrant/js-client-rest": "1.20.0",
56
57
  "cheerio": "1.2.0",
57
- "js-yaml": "5.4.2",
58
- "minio": "8.0.7",
59
- "oxfmt": "0.72.0",
58
+ "js-yaml": "5.5.0",
59
+ "oxfmt": "0.76.0",
60
60
  "sharp": "0.35.5",
61
- "turndown": "7.2.4",
62
- "uuid": "14.0.2",
61
+ "turndown": "7.2.5",
62
+ "uuid": "14.0.3",
63
63
  "web-push": "3.6.7",
64
- "zod": "4.6.5"
64
+ "zod": "4.6.7"
65
65
  },
66
66
  "publishConfig": {
67
67
  "access": "public"
@@ -1,115 +0,0 @@
1
- import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
2
-
3
- // ../storage/dist/src/client.js
4
- import { Client } from "minio";
5
-
6
- // ../storage/dist/src/cf-access-transport.js
7
- import * as https from "node:https";
8
- function createCfAccessTransport(config) {
9
- if (!config?.clientId || !config.clientSecret) {
10
- return void 0;
11
- }
12
- return {
13
- request(options, ...rest) {
14
- if (typeof options === "object" && !(options instanceof URL)) {
15
- const headers = options.headers ?? {};
16
- headers["CF-Access-Client-Id"] = config.clientId;
17
- headers["CF-Access-Client-Secret"] = config.clientSecret;
18
- options.headers = headers;
19
- }
20
- const request2 = https.request;
21
- return request2(options, ...rest);
22
- }
23
- };
24
- }
25
-
26
- // ../storage/dist/src/client.js
27
- function createMinioClient(config, cfAccess) {
28
- const resolved = config ?? {
29
- endPoint: process.env.MINIO_HOST ?? "",
30
- port: Number(process.env.MINIO_PORT),
31
- useSSL: process.env.MINIO_USE_SSL === void 0 ? !["localhost", "127.0.0.1"].includes(process.env.MINIO_HOST ?? "") : process.env.MINIO_USE_SSL === "true",
32
- accessKey: process.env.MINIO_ACCESS_KEY ?? "",
33
- secretKey: process.env.MINIO_SECRET_KEY ?? ""
34
- };
35
- const resolvedCfAccess = cfAccess ?? {
36
- clientId: process.env.CF_ACCESS_CLIENT_ID ?? "",
37
- clientSecret: process.env.CF_ACCESS_CLIENT_SECRET ?? ""
38
- };
39
- const transport = resolved.useSSL ? createCfAccessTransport(resolvedCfAccess) : void 0;
40
- if (resolved.useSSL && !transport) {
41
- throw new Error("CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET are required when useSSL is true.");
42
- }
43
- return new Client({
44
- endPoint: resolved.endPoint,
45
- port: resolved.port,
46
- useSSL: resolved.useSSL,
47
- accessKey: resolved.accessKey,
48
- secretKey: resolved.secretKey,
49
- ...transport && { transport }
50
- });
51
- }
52
-
53
- // ../storage/dist/index.js
54
- import { S3Error } from "minio";
55
-
56
- // ../storage/dist/src/errors.js
57
- var StorageOperationError = class extends Error {
58
- context;
59
- constructor(context, cause) {
60
- super(`Storage ${context.operation} failed for ${context.objectKey}`, {
61
- cause
62
- });
63
- this.name = "StorageOperationError";
64
- this.context = context;
65
- }
66
- };
67
-
68
- // ../storage/dist/src/storage-service.js
69
- function createStorageService(client, bucketName, pathConfig) {
70
- function buildObjectKey(path, isThumbnail) {
71
- return `${isThumbnail ? pathConfig.thumbnailPrefix : pathConfig.originalPrefix}/${path}`;
72
- }
73
- function wrapStorageError(operation, objectKey, isThumbnail, error) {
74
- throw new StorageOperationError({ operation, objectKey, bucketName, isThumbnail }, error);
75
- }
76
- return {
77
- async uploadImage(path, bytes, isThumbnail) {
78
- const objKey = buildObjectKey(path, isThumbnail);
79
- try {
80
- await client.putObject(bucketName, objKey, Buffer.from(bytes));
81
- } catch (error) {
82
- wrapStorageError("uploadImage", objKey, isThumbnail, error);
83
- }
84
- },
85
- async getImage(path, isThumbnail) {
86
- const objKey = buildObjectKey(path, isThumbnail);
87
- try {
88
- return await client.getObject(bucketName, objKey);
89
- } catch (error) {
90
- return wrapStorageError("getImage", objKey, isThumbnail, error);
91
- }
92
- },
93
- async getImageOrThrow(path, isThumbnail) {
94
- const objKey = buildObjectKey(path, isThumbnail);
95
- try {
96
- await client.statObject(bucketName, objKey);
97
- } catch (error) {
98
- wrapStorageError("getImageOrThrow", objKey, isThumbnail, error);
99
- }
100
- },
101
- async deleteImage(path, isThumbnail) {
102
- const objKey = buildObjectKey(path, isThumbnail);
103
- try {
104
- await client.removeObject(bucketName, objKey);
105
- } catch (error) {
106
- wrapStorageError("deleteImage", objKey, isThumbnail, error);
107
- }
108
- }
109
- };
110
- }
111
-
112
- export {
113
- createMinioClient,
114
- createStorageService
115
- };