refactor: new project struct (#8199)

packages/frontend/web -> packages/frontend/apps/web
packages/frontend/mobile -> packages/frontend/apps/mobile
packages/frontend/electron -> packages/frontend/apps/electron
This commit is contained in:
EYHN
2024-09-12 07:42:57 +00:00
parent 7c4eab6cd3
commit cc5a6e6d40
291 changed files with 139 additions and 134 deletions
@@ -0,0 +1,70 @@
import type { CookiesSetDetails } from 'electron';
import { logger } from './logger';
import { globalStateStorage } from './shared-storage/storage';
export function parseCookie(
cookieString: string,
url: string
): CookiesSetDetails {
const [nameValuePair, ...attributes] = cookieString
.split('; ')
.map(part => part.trim());
const [name, value] = nameValuePair.split('=');
const details: CookiesSetDetails = { url, name, value };
attributes.forEach(attribute => {
const [key, val] = attribute.split('=');
switch (key.toLowerCase()) {
case 'domain':
details.domain = val;
break;
case 'path':
details.path = val;
break;
case 'secure':
details.secure = true;
break;
case 'httponly':
details.httpOnly = true;
break;
case 'expires':
details.expirationDate = new Date(val).getTime() / 1000; // Convert to seconds
break;
case 'samesite':
if (
['unspecified', 'no_restriction', 'lax', 'strict'].includes(
val.toLowerCase()
)
) {
details.sameSite = val.toLowerCase() as
| 'unspecified'
| 'no_restriction'
| 'lax'
| 'strict';
}
break;
default:
// Handle other cookie attributes if needed
break;
}
});
return details;
}
export const isOfflineModeEnabled = () => {
try {
return (
// todo(pengx17): better abstraction for syncing flags with electron
// packages/common/infra/src/modules/feature-flag/entities/flags.ts
globalStateStorage.get('affine-flag:enable_offline_mode') ?? false
);
} catch (error) {
logger.error('Failed to get offline mode flag', error);
return false;
}
};