mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 15:32:36 +10:00
fix: duplicate page position bug (#1431)
This commit is contained in:
@ -261,35 +261,7 @@ export class PageService {
|
|||||||
|
|
||||||
if (isDuplicateInSameSpace) {
|
if (isDuplicateInSameSpace) {
|
||||||
// For duplicate in same space, position right after the original page
|
// For duplicate in same space, position right after the original page
|
||||||
let siblingQuery = this.db
|
nextPosition = generateJitteredKeyBetween(rootPage.position, null);
|
||||||
.selectFrom('pages')
|
|
||||||
.select(['position'])
|
|
||||||
.where('spaceId', '=', rootPage.spaceId)
|
|
||||||
.where('position', '>', rootPage.position);
|
|
||||||
|
|
||||||
if (rootPage.parentPageId) {
|
|
||||||
siblingQuery = siblingQuery.where(
|
|
||||||
'parentPageId',
|
|
||||||
'=',
|
|
||||||
rootPage.parentPageId,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
siblingQuery = siblingQuery.where('parentPageId', 'is', null);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextSibling = await siblingQuery
|
|
||||||
.orderBy('position', 'asc')
|
|
||||||
.limit(1)
|
|
||||||
.executeTakeFirst();
|
|
||||||
|
|
||||||
if (nextSibling) {
|
|
||||||
nextPosition = generateJitteredKeyBetween(
|
|
||||||
rootPage.position,
|
|
||||||
nextSibling.position,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
nextPosition = generateJitteredKeyBetween(rootPage.position, null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// For copy to different space, position at the end
|
// For copy to different space, position at the end
|
||||||
nextPosition = await this.nextPagePosition(spaceId);
|
nextPosition = await this.nextPagePosition(spaceId);
|
||||||
@ -434,25 +406,35 @@ export class PageService {
|
|||||||
attachment.id,
|
attachment.id,
|
||||||
newAttachmentId,
|
newAttachmentId,
|
||||||
);
|
);
|
||||||
await this.storageService.copy(attachment.filePath, newPathFile);
|
|
||||||
await this.db
|
try {
|
||||||
.insertInto('attachments')
|
await this.storageService.copy(attachment.filePath, newPathFile);
|
||||||
.values({
|
|
||||||
id: newAttachmentId,
|
await this.db
|
||||||
type: attachment.type,
|
.insertInto('attachments')
|
||||||
filePath: newPathFile,
|
.values({
|
||||||
fileName: attachment.fileName,
|
id: newAttachmentId,
|
||||||
fileSize: attachment.fileSize,
|
type: attachment.type,
|
||||||
mimeType: attachment.mimeType,
|
filePath: newPathFile,
|
||||||
fileExt: attachment.fileExt,
|
fileName: attachment.fileName,
|
||||||
creatorId: attachment.creatorId,
|
fileSize: attachment.fileSize,
|
||||||
workspaceId: attachment.workspaceId,
|
mimeType: attachment.mimeType,
|
||||||
pageId: newPageId,
|
fileExt: attachment.fileExt,
|
||||||
spaceId: spaceId,
|
creatorId: attachment.creatorId,
|
||||||
})
|
workspaceId: attachment.workspaceId,
|
||||||
.execute();
|
pageId: newPageId,
|
||||||
|
spaceId: spaceId,
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(
|
||||||
|
`Duplicate page: failed to copy attachment ${attachment.id}`,
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
// Continue with other attachments even if one fails
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.log(err);
|
this.logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user