refactor: image info filling
Signed-off-by: Varun Patil <radialapps@gmail.com>pulsejet/aio-hw-docs
parent
e396359011
commit
f0e1b00096
|
@ -128,8 +128,6 @@ export default defineComponent({
|
||||||
this.show = true;
|
this.show = true;
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
this.sections = sections;
|
this.sections = sections;
|
||||||
|
|
||||||
let done = 0;
|
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
|
|
||||||
// Filter out forbidden MIME types
|
// Filter out forbidden MIME types
|
||||||
|
@ -159,24 +157,10 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load metadata for all photos
|
// Load metadata for all photos
|
||||||
const calls = photos.map((p) => async () => {
|
await dav.fillImageInfo(photos, { tags: 1 }, (count) => {
|
||||||
try {
|
this.progress = Math.round((count * 100) / photos.length);
|
||||||
const url = API.Q(API.IMAGE_INFO(p.fileid), { tags: 1 });
|
|
||||||
const res = await axios.get<IImageInfo>(url);
|
|
||||||
p.datetaken = res.data.datetaken;
|
|
||||||
p.imageInfo = res.data;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to get date info for', p.fileid, error);
|
|
||||||
} finally {
|
|
||||||
done++;
|
|
||||||
this.progress = Math.round((done * 100) / photos.length);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for await (const _ of dav.runInParallel(calls, 8)) {
|
|
||||||
// nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already quit
|
// Check if already quit
|
||||||
if (!this.show || this.state !== state) return;
|
if (!this.show || this.state !== state) return;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { translate as t } from '@services/l10n';
|
||||||
import * as utils from '@services/utils';
|
import * as utils from '@services/utils';
|
||||||
import * as nativex from '@native';
|
import * as nativex from '@native';
|
||||||
|
|
||||||
import type { IFileInfo, IPhoto } from '@typings';
|
import type { IFileInfo, IImageInfo, IPhoto } from '@typings';
|
||||||
import type { ResponseDataDetailed, SearchResult } from 'webdav';
|
import type { ResponseDataDetailed, SearchResult } from 'webdav';
|
||||||
|
|
||||||
const GET_FILE_CHUNK_SIZE = 50;
|
const GET_FILE_CHUNK_SIZE = 50;
|
||||||
|
@ -344,3 +344,35 @@ export async function* movePhotos(photos: IPhoto[], destination: string, overwri
|
||||||
|
|
||||||
yield* runInParallel(calls, 10);
|
yield* runInParallel(calls, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill the imageInfo attributes of the given photos
|
||||||
|
*
|
||||||
|
* @param photos list of photos to fill
|
||||||
|
* @param query options
|
||||||
|
* @param query.tags whether to include tags in the response
|
||||||
|
* @param progress callback to report progress
|
||||||
|
*/
|
||||||
|
export async function fillImageInfo(photos: IPhoto[], query?: { tags?: number }, progress?: (count: number) => void) {
|
||||||
|
// Number of photos done
|
||||||
|
let done = 0;
|
||||||
|
|
||||||
|
// Load metadata for all photos
|
||||||
|
const calls = photos.map((p) => async () => {
|
||||||
|
try {
|
||||||
|
const url = API.Q(API.IMAGE_INFO(p.fileid), query ?? {});
|
||||||
|
const res = await axios.get<IImageInfo>(url);
|
||||||
|
p.datetaken = res.data.datetaken;
|
||||||
|
p.imageInfo = res.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to get image info for', p.fileid, error);
|
||||||
|
} finally {
|
||||||
|
done++;
|
||||||
|
progress?.(done);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for await (const _ of runInParallel(calls, 8)) {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue