mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:09:05 +00:00
Scanner delete albums when not found locally
This commit is contained in:
@@ -69,9 +69,8 @@ class PhotoScanner {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allUserScans.push(this.scanUser(user))
|
|
||||||
|
|
||||||
console.log(`Scanning ${user.username}...`)
|
console.log(`Scanning ${user.username}...`)
|
||||||
|
allUserScans.push(this.scanUser(user))
|
||||||
},
|
},
|
||||||
onCompleted: () => {
|
onCompleted: () => {
|
||||||
session.close()
|
session.close()
|
||||||
@@ -92,6 +91,7 @@ class PhotoScanner {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
console.log('SYNC ERROR', JSON.stringify(error))
|
||||||
this.pubsub.publish(EVENT_SCANNER_PROGRESS, {
|
this.pubsub.publish(EVENT_SCANNER_PROGRESS, {
|
||||||
scannerStatusUpdate: {
|
scannerStatusUpdate: {
|
||||||
progress: 0,
|
progress: 0,
|
||||||
@@ -123,6 +123,8 @@ class PhotoScanner {
|
|||||||
const driver = this.driver
|
const driver = this.driver
|
||||||
const scanAlbum = this.scanAlbum
|
const scanAlbum = this.scanAlbum
|
||||||
|
|
||||||
|
let foundAlbumIds = []
|
||||||
|
|
||||||
async function scanPath(path) {
|
async function scanPath(path) {
|
||||||
const list = fs.readdirSync(path)
|
const list = fs.readdirSync(path)
|
||||||
|
|
||||||
@@ -154,6 +156,9 @@ class PhotoScanner {
|
|||||||
console.log('Album already exists')
|
console.log('Album already exists')
|
||||||
|
|
||||||
const album = findAlbumResult.records[0].toObject().a.properties
|
const album = findAlbumResult.records[0].toObject().a.properties
|
||||||
|
|
||||||
|
foundAlbumIds.push(album.id)
|
||||||
|
|
||||||
scanAlbum(album)
|
scanAlbum(album)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@@ -192,6 +197,22 @@ class PhotoScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await scanPath(user.rootPath)
|
await scanPath(user.rootPath)
|
||||||
|
|
||||||
|
console.log('Found album ids', foundAlbumIds)
|
||||||
|
|
||||||
|
const session = this.driver.session()
|
||||||
|
|
||||||
|
const userAlbumsResult = await session.run(
|
||||||
|
'MATCH (u:User { id: {userId} })-[:OWNS]->(a:Album) WHERE NOT a.id IN {foundAlbums} DETACH DELETE a return a',
|
||||||
|
{ userId: user.id, foundAlbums: foundAlbumIds }
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Deleted ${userAlbumsResult.records.length} albums from ${user.username} that was not found locally`
|
||||||
|
)
|
||||||
|
|
||||||
|
session.close()
|
||||||
|
|
||||||
console.log('User scan complete')
|
console.log('User scan complete')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user