完成五人团队正式内用最小收口(07-18-small-team-internal-readiness)
这个提交包含在:
@@ -2,7 +2,7 @@ const fs = require("node:fs/promises");
|
||||
const fsSync = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const { S3Client, PutObjectCommand, GetObjectCommand } = require("@aws-sdk/client-s3");
|
||||
const { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } = require("@aws-sdk/client-s3");
|
||||
|
||||
class StorageNotFoundError extends Error {
|
||||
constructor(message) {
|
||||
@@ -119,6 +119,34 @@ async function writeBuffer({ config, key, buffer, contentType }) {
|
||||
return key;
|
||||
}
|
||||
|
||||
async function deleteObject({ config, storagePath }) {
|
||||
const parsed = parseStoragePath(storagePath);
|
||||
if (!parsed.key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed.driver === "s3") {
|
||||
const s3 = resolveS3Config(config);
|
||||
const client = getS3Client(config);
|
||||
await client.send(
|
||||
new DeleteObjectCommand({
|
||||
Bucket: s3.bucket,
|
||||
Key: parsed.key,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const absolutePath = ensureSafeLocalPath(config.storageDir, parsed.key);
|
||||
try {
|
||||
await fs.unlink(absolutePath);
|
||||
} catch (error) {
|
||||
if (error?.code !== "ENOENT") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function readFileBuffer({ config, storagePath }) {
|
||||
const parsed = parseStoragePath(storagePath);
|
||||
if (!parsed.key) {
|
||||
@@ -206,6 +234,7 @@ async function openReadStream({ config, storagePath }) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
deleteObject,
|
||||
StorageConfigError,
|
||||
StorageNotFoundError,
|
||||
openReadStream,
|
||||
@@ -213,4 +242,3 @@ module.exports = {
|
||||
readFileBuffer,
|
||||
writeBuffer,
|
||||
};
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户