111 lines
2.6 KiB
TypeScript
111 lines
2.6 KiB
TypeScript
// Helper functions for the application
|
|
|
|
// Date utility functions
|
|
export function MakeNewDate(input: string | number | Date): Date {
|
|
if (input instanceof Date) {
|
|
return input;
|
|
}
|
|
return new Date(input);
|
|
}
|
|
|
|
export function getDate(date: Date): number {
|
|
return date.getDate();
|
|
}
|
|
|
|
export function getMonth(date: Date): number {
|
|
return date.getMonth();
|
|
}
|
|
|
|
export function getYear(date: Date): number {
|
|
return date.getFullYear();
|
|
}
|
|
|
|
export function getDay(date: Date): number {
|
|
return date.getDay();
|
|
}
|
|
|
|
export function getDaysInBaseMonth(year: number, month: number): number {
|
|
return new Date(year, month + 1, 0).getDate();
|
|
}
|
|
|
|
// Encryption functions (placeholders - these should be properly implemented)
|
|
export function encryptDataWithStoredPassword(
|
|
_userId: string,
|
|
data: string,
|
|
): string {
|
|
// TODO: Implement proper encryption
|
|
// For now, return base64 encoded data as placeholder
|
|
return btoa(data);
|
|
}
|
|
|
|
export function decryptDataWithStoredPassword(
|
|
_userId: string,
|
|
encryptedData: string,
|
|
): string {
|
|
// TODO: Implement proper decryption
|
|
// For now, return base64 decoded data as placeholder
|
|
try {
|
|
return atob(encryptedData);
|
|
} catch {
|
|
return encryptedData; // Return as-is if not base64
|
|
}
|
|
}
|
|
|
|
export function tryDecryptDataWith(
|
|
userId: string,
|
|
encryptedData: string,
|
|
): string | null {
|
|
try {
|
|
return decryptDataWithStoredPassword(userId, encryptedData);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getEncryptionPassword(userId: string): string | null {
|
|
// TODO: Implement proper password retrieval
|
|
// For now, return null as placeholder
|
|
const userKey = `encryption_password_${userId}`;
|
|
try {
|
|
return globalThis.localStorage?.getItem(userKey);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getUserEncryptionKey(_userId: string): string | null {
|
|
// TODO: Implement proper key retrieval
|
|
return null;
|
|
}
|
|
|
|
export function getUserSkipKey(userId: string): string {
|
|
return `skip_encryption_${userId}`;
|
|
}
|
|
|
|
export function getUserSkipValue(userId: string): boolean {
|
|
const skipKey = getUserSkipKey(userId);
|
|
try {
|
|
return globalThis.localStorage?.getItem(skipKey) === "true";
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function setUserSkipKey(userId: string, skip: boolean): void {
|
|
const skipKey = `skip_encryption_${userId}`;
|
|
try {
|
|
if (skip) {
|
|
globalThis.localStorage?.setItem(skipKey, "true");
|
|
} else {
|
|
globalThis.localStorage?.removeItem(skipKey);
|
|
}
|
|
} catch {
|
|
// Ignore localStorage errors
|
|
}
|
|
}
|
|
|
|
export function createPublicId(userId: string): string {
|
|
// Create a public ID from user ID (simple implementation)
|
|
return btoa(userId).replace(/[+/=]/g, "").substring(0, 10);
|
|
}
|