1
Fork 0

Merge branch 'master' of github.com:viktorstrate/photoview

This commit is contained in:
viktorstrate 2019-08-12 16:08:48 +02:00
commit e0cfa9038b
4 changed files with 40 additions and 23 deletions

View File

@ -88,7 +88,7 @@ setInterval(scanner.scanAll, 1000 * 60 * 60 * 4)
// Specify port and path for GraphQL endpoint
const graphPath = '/graphql'
const endpointUrl = config.host
const endpointUrl = new URL(config.host)
// endpointUrl.port = process.env.GRAPHQL_LISTEN_PORT || 4001
/*
@ -148,7 +148,7 @@ httpServer.listen(
`🚀 GraphQL endpoint ready at ${new URL(server.graphqlPath, endpointUrl)}`
)
let subscriptionUrl = endpointUrl
let subscriptionUrl = new URL(endpointUrl)
subscriptionUrl.protocol = 'ws'
console.log(

View File

@ -17,6 +17,16 @@ async function addExifTags({ session, photo }) {
const rawTags = await exiftool.read(photo.path)
let iso = rawTags.ISO
if (typeof iso != 'Number') {
try {
iso = parseInt(iso)
} catch (e) {
console.log('Could not parse ISO as int', e, e.stack)
iso = undefined
}
}
const photoExif = {
camera: rawTags.Model,
maker: rawTags.Make,
@ -27,7 +37,7 @@ async function addExifTags({ session, photo }) {
fileSize: rawTags.FileSize,
exposure: rawTags.ShutterSpeedValue,
aperture: rawTags.ApertureValue,
iso: rawTags.ISO,
iso,
focalLength: rawTags.FocalLength,
flash: rawTags.Flash,
}
@ -69,6 +79,8 @@ export default async function processImage({ driver, markFinishedImage }, id) {
if (urlResult.records.length == 2) {
markFinishedImage()
session.close()
console.log('Skipping image', photo.path)
return
}
@ -80,8 +92,12 @@ export default async function processImage({ driver, markFinishedImage }, id) {
{ id }
)
await fs.remove(imagePath)
await fs.mkdirp(imagePath)
try {
await fs.remove(imagePath)
await fs.mkdirp(imagePath)
} catch (e) {
console.error('Could not remove old image, and make directory', e, e.stack)
}
let originalPath = photo.path

View File

@ -2,7 +2,7 @@ export default function scanAll({ driver, scanUser }) {
return new Promise((resolve, reject) => {
let session = driver.session()
let allUserScans = []
let usersToScan = []
session.run('MATCH (u:User) return u').subscribe({
onNext: record => {
@ -13,21 +13,21 @@ export default function scanAll({ driver, scanUser }) {
return
}
allUserScans.push(
scanUser(user).catch(reason => {
usersToScan.push(user)
},
onCompleted: async () => {
session.close()
for (let user of usersToScan) {
try {
await scanUser(user)
} catch (reason) {
console.log(
`User scan exception for user ${user.username} ${reason}`
)
reject(reason)
})
)
},
onCompleted: () => {
session.close()
Promise.all(allUserScans).then(() => {
resolve()
})
}
}
},
onError: error => {
session.close()

View File

@ -7,7 +7,6 @@ export default async function scanUser({ driver, scanAlbum }, user) {
console.log('Scanning user', user.username, 'at', user.path)
let foundAlbumIds = []
let albumScanPromises = []
async function scanPath(path, parentAlbum) {
console.log('SCAN PATH', path)
@ -52,7 +51,7 @@ export default async function scanUser({ driver, scanAlbum }, user) {
foundImageOrAlbum = true
nextParentAlbum = album.id
foundAlbumIds.push(album.id)
albumScanPromises.push(scanAlbum(album))
await scanAlbum(album)
continue
}
@ -108,7 +107,7 @@ export default async function scanUser({ driver, scanAlbum }, user) {
}
foundAlbumIds.push(album.id)
albumScanPromises.push(scanAlbum(album))
await scanAlbum(album)
session.close()
}
@ -146,7 +145,11 @@ export default async function scanUser({ driver, scanAlbum }, user) {
)
for (const albumId of deletedAlbumIds) {
await fs.remove(getAlbumCachePath(albumId))
try {
await fs.remove(getAlbumCachePath(albumId))
} catch (e) {
console.error('Error while trying to delete album from cache', e, e.stack)
}
}
console.log(
@ -155,7 +158,5 @@ export default async function scanUser({ driver, scanAlbum }, user) {
session.close()
await Promise.all(albumScanPromises)
console.log('User scan complete')
}