mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:29:15 +00:00
Mark as album if contains subalbums
This commit is contained in:
@@ -38,7 +38,7 @@ const typeDefs = fs
|
||||
import usersResolver from './resolvers/users'
|
||||
import scannerResolver from './resolvers/scanner'
|
||||
import photosResolver from './resolvers/photos'
|
||||
import { isRawImage } from './scanner/utils'
|
||||
import { isRawImage, getImageCachePath } from './scanner/utils'
|
||||
|
||||
const resolvers = [usersResolver, scannerResolver, photosResolver]
|
||||
|
||||
@@ -137,7 +137,7 @@ app.use('/images/:id/:image', async function(req, res) {
|
||||
const session = driver.session()
|
||||
|
||||
const result = await session.run(
|
||||
'MATCH (p:Photo { id: {id} })<-[:CONTAINS]-(:Album)<-[:OWNS]-(u:User) RETURN p as photo, u.id as userId',
|
||||
'MATCH (p:Photo { id: {id} })<-[:CONTAINS]-(a:Album)<-[:OWNS]-(u:User) RETURN p as photo, u.id as userId, a.id as albumId',
|
||||
{
|
||||
id,
|
||||
}
|
||||
@@ -148,6 +148,7 @@ app.use('/images/:id/:image', async function(req, res) {
|
||||
}
|
||||
|
||||
const userId = result.records[0].get('userId')
|
||||
const albumId = result.records[0].get('albumId')
|
||||
const photo = result.records[0].get('photo').properties
|
||||
|
||||
if (userId != user.id) {
|
||||
@@ -156,7 +157,7 @@ app.use('/images/:id/:image', async function(req, res) {
|
||||
|
||||
session.close()
|
||||
|
||||
let imagePath = path.resolve(config.cachePath, 'images', id, image)
|
||||
let imagePath = path.resolve(getImageCachePath(id, albumId), image)
|
||||
|
||||
if (!(await fs.exists(imagePath))) {
|
||||
if (image == 'thumbnail.jpg') {
|
||||
|
||||
@@ -15,7 +15,7 @@ export default async function processImage({ driver, addFinishedImage }, id) {
|
||||
)
|
||||
|
||||
await session.run(
|
||||
`MATCH (p:Photo { id: {id} })-[rel]->(url:PhotoURL) DELETE url, rel`,
|
||||
`MATCH (p:Photo { id: {id} })-->(urls:PhotoURL) DETACH DELETE urls`,
|
||||
{ id }
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export default async function scanUser({ driver, scanAlbum }, user) {
|
||||
console.log('SCAN PATH', path)
|
||||
const list = fs.readdirSync(path)
|
||||
|
||||
let foundImage = false
|
||||
let foundImageOrAlbum = false
|
||||
let newAlbums = []
|
||||
|
||||
for (const item of list) {
|
||||
@@ -49,6 +49,7 @@ export default async function scanUser({ driver, scanAlbum }, user) {
|
||||
const album = findAlbumResult.records[0].toObject().a.properties
|
||||
console.log('Found existing album', album.title)
|
||||
|
||||
foundImageOrAlbum = true
|
||||
nextParentAlbum = album.id
|
||||
foundAlbumIds.push(album.id)
|
||||
albumScanPromises.push(scanAlbum(album))
|
||||
@@ -58,6 +59,8 @@ export default async function scanUser({ driver, scanAlbum }, user) {
|
||||
|
||||
if (imagesInDirectory) {
|
||||
console.log(`Found new album at ${itemPath}`)
|
||||
foundImageOrAlbum = true
|
||||
|
||||
const session = driver.session()
|
||||
|
||||
console.log('Adding album')
|
||||
@@ -113,12 +116,12 @@ export default async function scanUser({ driver, scanAlbum }, user) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!foundImage && (await isImage(itemPath))) {
|
||||
foundImage = true
|
||||
if (!foundImageOrAlbum && (await isImage(itemPath))) {
|
||||
foundImageOrAlbum = true
|
||||
}
|
||||
}
|
||||
|
||||
return { foundImage, newAlbums }
|
||||
return { foundImage: foundImageOrAlbum, newAlbums }
|
||||
}
|
||||
|
||||
await scanPath(user.rootPath)
|
||||
@@ -126,14 +129,16 @@ export default async function scanUser({ driver, scanAlbum }, user) {
|
||||
const session = driver.session()
|
||||
|
||||
const userAlbumsResult = await session.run(
|
||||
`MATCH (u:User { id: {userId} })-[:OWNS]->(a:Album)-[:CONTAINS]->(p:Photo)
|
||||
`MATCH (u:User { id: {userId} })-[:OWNS]->(a:Album)
|
||||
WHERE NOT a.id IN {foundAlbums}
|
||||
WITH a, p, a.id AS albumId
|
||||
DETACH DELETE a, p
|
||||
OPTIONAL MATCH (a)-[:CONTAINS]->(p:Photo)-->(photoTail)
|
||||
WITH a, p, photoTail, a.id AS albumId
|
||||
DETACH DELETE a, p, photoTail
|
||||
RETURN albumId`,
|
||||
{ userId: user.id, foundAlbums: foundAlbumIds }
|
||||
)
|
||||
|
||||
console.log('FOUND ALBUM IDS', foundAlbumIds)
|
||||
const deletedAlbumIds = userAlbumsResult.records.map(record =>
|
||||
record.get('albumId')
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user