mirror of
https://github.com/ever-co/ever-gauzy.git
synced 2026-10-02 01:54:50 +08:00
refactor: getLastTimeSlotImage and localImage methods with additional checks and logic
This commit is contained in:
@@ -1702,7 +1702,9 @@ export class TimeTrackerComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
public async getLastTimeSlotImage(arg): Promise<void> {
|
||||
if (this._isOffline) return;
|
||||
if (this._isOffline || this.lastTimeSlot?.id === arg?.timeSlotId) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await this.timeTrackerService.getTimeSlot(arg);
|
||||
const { screenshots = [] } = res || {};
|
||||
@@ -1728,24 +1730,40 @@ export class TimeTrackerComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
}
|
||||
|
||||
public async localImage(img, originalBase64Image?: string): Promise<void> {
|
||||
public async localImage(
|
||||
img: { thumbUrl?: string; recordedAt?: string; fullUrl?: string } | string,
|
||||
originalBase64Image?: string
|
||||
): Promise<void> {
|
||||
try {
|
||||
const convScreenshot =
|
||||
img && img.thumbUrl ? await this._imageViewerService.getBase64ImageFromUrl(img.thumbUrl) : img;
|
||||
localStorage.setItem(
|
||||
'lastScreenCapture',
|
||||
JSON.stringify({
|
||||
thumbUrl: convScreenshot,
|
||||
textTime: moment().fromNow(),
|
||||
createdAt: Date.now(),
|
||||
recordedAt: Date.now(),
|
||||
...(originalBase64Image && {
|
||||
fullUrl: originalBase64Image
|
||||
})
|
||||
})
|
||||
);
|
||||
// Determine the fullUrl, prioritizing originalBase64Image if provided
|
||||
const fullUrl = originalBase64Image || (typeof img === 'object' ? img.fullUrl : undefined);
|
||||
|
||||
// Fetch the thumbnail or use the image string directly if img is a string
|
||||
const thumbUrl =
|
||||
typeof img === 'object' && img.thumbUrl
|
||||
? await this._imageViewerService.getBase64ImageFromUrl(img.thumbUrl)
|
||||
: typeof img === 'string'
|
||||
? img
|
||||
: undefined;
|
||||
|
||||
// Set timestamp, preferring recordedAt if available
|
||||
const timestamp = typeof img === 'object' && img.recordedAt ? new Date(img.recordedAt) : new Date();
|
||||
|
||||
if (fullUrl && thumbUrl) {
|
||||
const screenCaptureData = {
|
||||
fullUrl,
|
||||
thumbUrl,
|
||||
textTime: moment(timestamp).fromNow(),
|
||||
createdAt: timestamp,
|
||||
recordedAt: timestamp
|
||||
};
|
||||
|
||||
localStorage.setItem('lastScreenCapture', JSON.stringify(screenCaptureData));
|
||||
} else {
|
||||
this._loggerService.warn('WARN: Invalid image data: missing fullUrl or thumbUrl.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('ERROR', error);
|
||||
this._loggerService.error('ERROR: Storing image:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user