profile-plus
Version:
### IOS
41 lines • 1.53 kB
JavaScript
import { Capacitor } from '@capacitor/core';
// currently use for generate
export function generateRandomName(format) {
const timestamp = new Date().getTime();
const randomString = Math.random().toString(15).substring(7); // Generate a random string
return format
? `${timestamp}_${randomString}.${format}`
: `${timestamp}_${randomString}`;
}
/**
* Fixes the image path for Android devices during development.
* Replaces 'localhost' with the appropriate site root URL.
* @param croppedImage
* @returns
*/
export function replaceLocalhostWithSiteRoot(croppedImage) {
let imageSrc = croppedImage;
if (imageSrc &&
process.env.NODE_ENV !== 'production' &&
Capacitor.getPlatform() === 'android') {
if (imageSrc.includes('localhost')) {
imageSrc = imageSrc.replace(/http\:\/\/localhost\:\d+/, process.env.SITE_ROOT);
}
}
return imageSrc;
}
/**
* Generates a unique file name based on the original file name.
* Example: `originalName.jpg` -> `originalName_1633024800000_abcd12.jpg`
*
* @param originalName
* @returns
*/
export function generateUniqueFileName(originalName) {
const ext = originalName.substring(originalName.lastIndexOf('.') + 1);
const base = originalName.substring(0, originalName.lastIndexOf('.'));
const timestamp = Date.now();
const randomStr = Math.random().toString(36).substring(2, 8); // 6-char random string
return `${base}_${timestamp}_${randomStr}.${ext}`;
}
//# sourceMappingURL=helper.js.map