mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 08:32:38 +10:00
fix: duplicate page position bug (#1431)
This commit is contained in:
@ -261,35 +261,7 @@ export class PageService {
|
||||
|
||||
if (isDuplicateInSameSpace) {
|
||||
// For duplicate in same space, position right after the original page
|
||||
let siblingQuery = this.db
|
||||
.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 {
|
||||
// For copy to different space, position at the end
|
||||
nextPosition = await this.nextPagePosition(spaceId);
|
||||
@ -434,7 +406,10 @@ export class PageService {
|
||||
attachment.id,
|
||||
newAttachmentId,
|
||||
);
|
||||
|
||||
try {
|
||||
await this.storageService.copy(attachment.filePath, newPathFile);
|
||||
|
||||
await this.db
|
||||
.insertInto('attachments')
|
||||
.values({
|
||||
@ -452,7 +427,14 @@ export class PageService {
|
||||
})
|
||||
.execute();
|
||||
} catch (err) {
|
||||
this.logger.log(err);
|
||||
this.logger.error(
|
||||
`Duplicate page: failed to copy attachment ${attachment.id}`,
|
||||
err,
|
||||
);
|
||||
// Continue with other attachments even if one fails
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user