Skip to content

Commit

Permalink
fix: better handling of update file metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bensandee committed Feb 23, 2024
1 parent 04d23b5 commit 71f4bdf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export class ImageRepositoryScanner implements Lifecycle {
private async addNewFile(filename: string) {
logger.debug(`adding new image ${filename}`);
const metadata = await this.getFileMetadata(filename);
const newImage = new Image({ filename, ...metadata });
const newImage = new Image({
filename,
...metadata,
});
logger.trace(newImage, "image data");
await newImage.save();
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/updatefilemetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe("updateFileMetadata", () => {
const goodImageId = await getGoodImageId();
const image = await Image.findById(goodImageId);
expect(image).toBeDefined();

expect(image?.description_from_exif).toBe(true);
if (!image) throw new Error("image is undefined");
expect(image.description).toBe("blarg");
expect(image.description_from_exif).toBe(true);

image.description_from_exif = false;
await image.save();
Expand Down
5 changes: 3 additions & 2 deletions src/tools/updatefilemetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export const updateFileMetadata = async (fs: FilesystemRepository) => {
const limit = pLimit(4);

const promises = images
.filter((image) => image.deleted === false)
.filter((image) => !image.deleted)
.filter((image) => !image.description_from_exif)
.filter((image) => image.description != null && image.description !== "")
.map((image) =>
limit(async () => {
const base = image.filename;
logger.info(`Updating description for ${base}`);
console.log(`Updating description for ${base}`);
const retval = await fs.updateImageDescription(
base,
image.description ?? "",
Expand Down
Binary file modified test_resources/test_DSC_7020.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 71f4bdf

Please sign in to comment.