Add comprehensive models and script for handling inline scripts and structured data
- Implement `remove-inline-scripts.js` to externalize Next.js inline scripts, enhancing CSP compliance. - Add models for `Book`, `Character`, `Story`, `Editor`, `System`, and `BookSerie` with relevant properties and utilities. - Include macOS entitlements plist for app development with advanced permissions. - Add utility functions to handle script hashing, cookie management, and content formatting.
This commit is contained in:
92
lib/models/User.ts
Normal file
92
lib/models/User.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import {SelectBoxProps} from "@/shared/interface";
|
||||
import {BookProps} from "@/lib/models/Book";
|
||||
import {SessionProps} from "@/lib/models/Session";
|
||||
|
||||
export interface Author {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UserProps {
|
||||
id: string;
|
||||
name: string;
|
||||
lastName: string;
|
||||
username: string;
|
||||
authorName?: string;
|
||||
email?: string;
|
||||
accountVerified?: boolean;
|
||||
termsAccepted?: boolean;
|
||||
aiUsage: number,
|
||||
apiKeys: {
|
||||
gemini: boolean
|
||||
openai: boolean,
|
||||
anthropic: boolean,
|
||||
},
|
||||
books?: BookProps[];
|
||||
guideTour?: GuideTour[];
|
||||
subscription?: Subscription[];
|
||||
writingLang: number;
|
||||
writingLevel: number;
|
||||
ritePoints: number;
|
||||
creditsBalance:number;
|
||||
groupId: number;
|
||||
}
|
||||
|
||||
export interface GuideTour {
|
||||
[key: string]: boolean;
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
subType: string;
|
||||
subTier: number;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
export const writingLevel: SelectBoxProps[] = [
|
||||
{value: '0', label: 'Sélectionner un niveau d\'écriture'},
|
||||
{value: '1', label: 'Je suis débutant'},
|
||||
{value: '2', label: 'Je suis intermédiaire'},
|
||||
{value: '3', label: 'Je suis avancé'},
|
||||
];
|
||||
|
||||
export default class User {
|
||||
static getCurrentSubscription(user: UserProps | null, type: "quill-sense" | "use-your-keys"): Subscription | null {
|
||||
if (!user || !user.subscription || user.subscription.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return user.subscription.find((sub: Subscription): boolean => {
|
||||
return sub.subType === type && sub.status;
|
||||
}) || null;
|
||||
}
|
||||
static getWritingLevel(level: number): string {
|
||||
switch (level) {
|
||||
case 1:
|
||||
return 'Débutant';
|
||||
case 2:
|
||||
return 'Intermédiaire';
|
||||
case 3:
|
||||
return 'Avancé';
|
||||
default:
|
||||
return 'Débutant';
|
||||
}
|
||||
}
|
||||
|
||||
static guideTourDone(guide: GuideTour[], tour: string): boolean {
|
||||
if (!guide || !tour) return false;
|
||||
return guide.find((guide: GuideTour): boolean => guide[tour]) === undefined;
|
||||
}
|
||||
|
||||
static setNewGuideTour(session: SessionProps, tour: string): SessionProps {
|
||||
const newGuideTour: { [key: string]: boolean }[] = [
|
||||
...(session?.user?.guideTour ?? []),
|
||||
{[tour]: true}
|
||||
];
|
||||
return {
|
||||
...session,
|
||||
user: {
|
||||
...session?.user as UserProps,
|
||||
guideTour: newGuideTour
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user