Merge branch 'fix/post_import_if' into 'develop'
fix: questionable if statements in note import Co-authored-by: 老周部落 <laozhoubuluo@gmail.com> See merge request firefish/firefish!10771
This commit is contained in:
commit
c0f7939a93
3 changed files with 31 additions and 9 deletions
|
@ -53,7 +53,11 @@ function processMastoFile(fn: string, path: string, dir: string, uid: string) {
|
|||
continue;
|
||||
}
|
||||
for (const attachment of note.object.attachment) {
|
||||
const url = attachment.url.replaceAll("..", "");
|
||||
// The url in some Mastodon import files do not start with /media_attachments/.
|
||||
// If this is not handled properly, these users not be able to import images in their posts.
|
||||
const url = attachment.url
|
||||
.replaceAll("..", "")
|
||||
.replaceAll(/.*\/media_attachments\//g, "/media_attachments/");
|
||||
if (url.indexOf("\0") !== -1) {
|
||||
logger.error(`Found Poison Null Bytes Attack: ${url}`);
|
||||
reject();
|
||||
|
|
|
@ -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 a new issue