Merge branch 'fix/post_import_if' into 'develop'
Draft: fix: questionable if statements in note import See merge request firefish/firefish!10771
This commit is contained in:
commit
0c8d201b5a
|
@ -56,10 +56,6 @@ 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
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue