Skip to content

Commit

Permalink
fix: memos image import
Browse files Browse the repository at this point in the history
  • Loading branch information
blinko-space committed Dec 2, 2024
1 parent 2f8ba8e commit 66973aa
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/server/plugins/memos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,25 @@ export class Memos {
continue;
}

const fileName = row?.filename;
const fileName = row?.filename ?? '';
const filePath = UPLOAD_FILE_PATH + '/' + fileName;
await fs.writeFile(filePath, row!.blob);
let newFileName = fileName.split('/').pop() || '';
const hasSameFile = await fs.access(filePath).then(() => true).catch(() => false);
if (row?.blob) {
if (hasSameFile) {
const extension = fileName.split('.').pop() || '';
const originalName = fileName.split('.').slice(0, -1).join('.');
newFileName = `${originalName}_${Date.now()}.${extension}`;
await fs.writeFile(UPLOAD_FILE_PATH + '/' + newFileName, row!.blob);
} else {
await fs.writeFile(filePath, row!.blob);
}
}

await prisma.attachments.create({
data: {
name: row?.filename,
path: '/api/file/' + fileName,
path: '/api/file/' + newFileName,
size: row?.size,
noteId: node.id,
}
Expand Down

0 comments on commit 66973aa

Please sign in to comment.