refactor: structure
This commit is contained in:
parent
48254ceec0
commit
81f8aeeb7c
1 changed files with 5 additions and 24 deletions
|
|
@ -715,7 +715,7 @@ export class UserController extends Controller {
|
||||||
new Promise<string[]>((resolve, reject) => {
|
new Promise<string[]>((resolve, reject) => {
|
||||||
const item: string[] = [];
|
const item: string[] = [];
|
||||||
|
|
||||||
const stream = minio.listObjectsV2(MINIO_BUCKET, `${attachmentLocation(userId)}/`);
|
const stream = minio.listObjectsV2(MINIO_BUCKET, fileLocation.user.attachment(userId));
|
||||||
|
|
||||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
stream.on("data", (v) => v && v.name && item.push(v.name));
|
||||||
stream.on("end", () => resolve(item));
|
stream.on("end", () => resolve(item));
|
||||||
|
|
@ -784,10 +784,6 @@ export class UserController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachmentLocation(uid: string) {
|
|
||||||
return `user-attachment/${uid}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Route("api/v1/user/{userId}/profile-image")
|
@Route("api/v1/user/{userId}/profile-image")
|
||||||
@Tags("User")
|
@Tags("User")
|
||||||
export class UserProfileController extends Controller {
|
export class UserProfileController extends Controller {
|
||||||
|
|
@ -866,22 +862,7 @@ export class UserAttachmentController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound");
|
throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound");
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = await new Promise<string[]>((resolve, reject) => {
|
return await listFile(fileLocation.user.attachment(userId));
|
||||||
const item: string[] = [];
|
|
||||||
|
|
||||||
const stream = minio.listObjectsV2(MINIO_BUCKET, `${attachmentLocation(userId)}/`);
|
|
||||||
|
|
||||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
|
||||||
stream.on("end", () => resolve(item));
|
|
||||||
stream.on("error", () => reject(new Error("MinIO error.")));
|
|
||||||
});
|
|
||||||
|
|
||||||
return await Promise.all(
|
|
||||||
list.map(async (v) => ({
|
|
||||||
name: v.split("/").at(-1) as string,
|
|
||||||
url: await minio.presignedGetObject(MINIO_BUCKET, v, 12 * 60 * 60),
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
|
@ -897,10 +878,10 @@ export class UserAttachmentController extends Controller {
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
payload.file.map(async (v) => ({
|
payload.file.map(async (v) => ({
|
||||||
name: v,
|
name: v,
|
||||||
url: await minio.presignedGetObject(MINIO_BUCKET, `${attachmentLocation(userId)}/${v}`),
|
url: await minio.presignedGetObject(MINIO_BUCKET, fileLocation.user.attachment(userId, v)),
|
||||||
uploadUrl: await minio.presignedPutObject(
|
uploadUrl: await minio.presignedPutObject(
|
||||||
MINIO_BUCKET,
|
MINIO_BUCKET,
|
||||||
`${attachmentLocation(userId)}/${v}`,
|
fileLocation.user.attachment(userId, v),
|
||||||
12 * 60 * 60,
|
12 * 60 * 60,
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
|
|
@ -911,7 +892,7 @@ export class UserAttachmentController extends Controller {
|
||||||
async deleteAttachment(@Path() userId: string, @Body() payload: { file: string[] }) {
|
async deleteAttachment(@Path() userId: string, @Body() payload: { file: string[] }) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
payload.file.map(async (v) => {
|
payload.file.map(async (v) => {
|
||||||
await minio.removeObject(MINIO_BUCKET, `${attachmentLocation(userId)}/${v}`, {
|
await minio.removeObject(MINIO_BUCKET, fileLocation.user.attachment(userId, v), {
|
||||||
forceDelete: true,
|
forceDelete: true,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue