Merge branch 'fix/post_import_if' into 'develop'

Draft: fix: questionable if statements in note import

Co-authored-by: naskya <m@naskya.net>

See merge request firefish/firefish!10771
This commit is contained in:
laozhoubuluo 2024-05-07 19:42:58 +00:00
commit a1edc8c6b7
3 changed files with 27 additions and 13 deletions

6
.gitignore vendored
View File

@ -50,16 +50,12 @@ api-docs.json
*.log
*.code-workspace
.DS_Store
files/
/files
ormconfig.json
packages/backend/assets/instance.css
packages/backend/assets/sounds/None.mp3
packages/backend/assets/LICENSE
!/packages/backend/queue/processors/db
!/packages/backend/src/db
!/packages/backend/src/server/api/endpoints/drive/files
packages/megalodon/lib
packages/megalodon/.idea

View File

@ -59,18 +59,27 @@ export async function importCkPost(
userId: user.id,
});
// FIXME: What is this condition?
if (note != null && (note.fileIds?.length || 0) < files.length) {
// If an import is completely successful at once, the order should not be out of order.
// If it takes multiple imports to complete, the order is not guaranteed to be consistent.
if (note != null && files.length > 0) {
const addFiles: DriveFile[] = [];
for (const file of files) {
if (!note.fileIds.includes(file.id)) {
addFiles.push(file);
}
}
const update: Partial<Note> = {};
update.fileIds = files.map((x) => x.id);
update.fileIds = addFiles.map((x) => x.id);
if (update.fileIds != null) {
await NoteFiles.delete({ noteId: note.id });
await NoteFiles.insert(
update.fileIds.map((fileId) => ({ noteId: note?.id, fileId })),
);
}
update.fileIds = note.fileIds.concat(update.fileIds);
await Notes.update(note.id, update);
await NoteEdits.insert({
id: genId(),

View File

@ -85,18 +85,27 @@ export async function importMastoPost(
userId: user.id,
});
// FIXME: What is this condition?
if (note != null && (note.fileIds?.length || 0) < files.length) {
// If an import is completely successful at once, the order should not be out of order.
// If it takes multiple imports to complete, the order is not guaranteed to be consistent.
if (note != null && files.length > 0) {
const addFiles: DriveFile[] = [];
for (const file of files) {
if (!note.fileIds.includes(file.id)) {
addFiles.push(file);
}
}
const update: Partial<Note> = {};
update.fileIds = files.map((x) => x.id);
update.fileIds = addFiles.map((x) => x.id);
if (update.fileIds != null) {
await NoteFiles.delete({ noteId: note.id });
await NoteFiles.insert(
update.fileIds.map((fileId) => ({ noteId: note?.id, fileId })),
);
}
update.fileIds = note.fileIds.concat(update.fileIds);
await Notes.update(note.id, update);
await NoteEdits.insert({
id: genId(),