Skip to content

Commit

Permalink
Introduce interface ThumbnailGenerationLogFileContent.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomoyukiAota committed Dec 12, 2024
1 parent 0634f39 commit 95a9df0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src-shared/thumbnail/cache/thumbnail-cache-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ export function getOriginalFilePath(thumbnailFilePath: string): string {
return originalFilePath;
}

const lastModifiedKey = 'LastModified';
const isThumbnailFileCreatedKey = 'IsThumbnailFileCreated';
interface ThumbnailGenerationLogFileContent {
LastModified: string;
IsThumbnailFileCreated: boolean;
}

export async function createThumbnailGenerationLogFile(srcFilePath: string, thumbnailFileDir: string, isThumbnailFileCreated: boolean, logger: PrependedLogger) {
const srcFileName = pathModule.basename(srcFilePath);
const lastModified = fsExtra.statSync(srcFilePath).mtime.toISOString();
const fileContentObj = {};
fileContentObj[lastModifiedKey] = lastModified;
fileContentObj[isThumbnailFileCreatedKey] = isThumbnailFileCreated;
const fileContentObj: ThumbnailGenerationLogFileContent = {
LastModified: lastModified,
IsThumbnailFileCreated: isThumbnailFileCreated
};
const fileContentStr = JSON.stringify(fileContentObj, null, 2);
const logFilePath = pathModule.join(thumbnailFileDir, `${srcFileName}.log.json`);

Expand Down Expand Up @@ -138,15 +141,15 @@ export function lastModifiedMatchBetweenSrcFileAndThumbnailGenerationLogFile(src
return false;
}

let fileContentObj;
let fileContentObj: ThumbnailGenerationLogFileContent;
try {
fileContentObj = JSON.parse(fileContentStr);
} catch (error) {
Logger.warn(`Failed to parse the content of the log file "${logFilePath}" as JSON format. The log file is for thumbnail generation result of "${srcFilePath}". error: ${error}`, error);
return false;
}

const lastModifiedFromLogFile = fileContentObj[lastModifiedKey];
const lastModifiedFromLogFile = fileContentObj.LastModified;
if (!lastModifiedFromLogFile)
return false;

Expand Down

0 comments on commit 95a9df0

Please sign in to comment.