Remove Act, AutoUpdater, and Book IPC modules alongside associated database logic.
This commit is contained in:
@@ -1,104 +1,93 @@
|
||||
import axios, {AxiosResponse, Method} from "axios";
|
||||
import {configs, isDesktop} from "@/lib/configs";
|
||||
|
||||
type ContentType = 'application/json' | 'multipart/form-data';
|
||||
|
||||
interface ApiRequestConfig {
|
||||
method: Method;
|
||||
url: string;
|
||||
auth: string;
|
||||
lang?: string;
|
||||
params?: Record<string, unknown>;
|
||||
data?: unknown;
|
||||
contentType?: ContentType;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
statusCode: number;
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
this.name = 'ApiError';
|
||||
}
|
||||
}
|
||||
|
||||
function handleApiError(error: unknown): never {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const serverMessage: string = error.response?.data?.message || error.response?.data || error.message;
|
||||
const statusCode: number = error.response?.status ?? 500;
|
||||
throw new ApiError(serverMessage, statusCode);
|
||||
} else if (error instanceof Error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
throw new Error('An unexpected error occurred');
|
||||
}
|
||||
|
||||
async function apiRequest<T>(config: ApiRequestConfig): Promise<T> {
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${config.auth}`
|
||||
};
|
||||
|
||||
if (config.contentType) {
|
||||
headers['Content-Type'] = config.contentType;
|
||||
}
|
||||
|
||||
const response: AxiosResponse<T> = await axios({
|
||||
method: config.method,
|
||||
headers,
|
||||
params: {
|
||||
lang: config.lang ?? 'fr',
|
||||
plateforme: isDesktop ? 'desktop' : 'web',
|
||||
...config.params
|
||||
},
|
||||
url: configs.apiUrl + config.url,
|
||||
data: config.data
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error: unknown) {
|
||||
handleApiError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function apiGet<T>(url: string, auth: string, lang: string = "fr", params: Record<string, unknown> = {}): Promise<T> {
|
||||
return apiRequest<T>({method: 'GET', url, auth, lang, params});
|
||||
}
|
||||
|
||||
export async function apiPost<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
return apiRequest<T>({method: 'POST', url, auth, lang, data, contentType: 'application/json'});
|
||||
}
|
||||
|
||||
export async function apiPut<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
return apiRequest<T>({method: 'PUT', url, auth, lang, data, contentType: 'application/json'});
|
||||
}
|
||||
|
||||
export async function apiPatch<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
return apiRequest<T>({method: 'PATCH', url, auth, lang, data, contentType: 'application/json'});
|
||||
}
|
||||
|
||||
export async function apiDelete<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
return apiRequest<T>({method: 'DELETE', url, auth, lang, data, contentType: 'application/json'});
|
||||
}
|
||||
|
||||
export async function apiPostPublic<T>(url: string, data: object, lang: string = "fr"): Promise<T> {
|
||||
try {
|
||||
const response: AxiosResponse<T> = await axios({
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
params: {lang, plateforme: isDesktop ? 'desktop' : 'web'},
|
||||
url: configs.apiUrl + url,
|
||||
data
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: unknown) {
|
||||
handleApiError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function apiUpload<T>(url: string, file: File, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const formData: FormData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
return apiRequest<T>({method: 'POST', url, auth, lang, data: formData, contentType: 'multipart/form-data'});
|
||||
}
|
||||
import {fetch} from "@tauri-apps/plugin-http";
|
||||
import {configs} from "@/lib/configs";
|
||||
|
||||
export class ApiError extends Error {
|
||||
statusCode: number;
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
this.name = 'ApiError';
|
||||
}
|
||||
}
|
||||
|
||||
function buildUrl(url: string, params: Record<string, unknown> = {}, lang: string = "fr"): string {
|
||||
const fullUrl = new URL(url, configs.apiUrl);
|
||||
fullUrl.searchParams.set("lang", lang);
|
||||
fullUrl.searchParams.set("plateforme", "desktop");
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value !== undefined && value !== null) fullUrl.searchParams.set(key, String(value));
|
||||
}
|
||||
return fullUrl.toString();
|
||||
}
|
||||
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => ({message: response.statusText}));
|
||||
throw new ApiError(body.message || body || response.statusText, response.status);
|
||||
}
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export async function apiGet<T>(url: string, auth: string, lang: string = "fr", params: Record<string, unknown> = {}): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, params, lang), {
|
||||
method: "GET",
|
||||
headers: {"Authorization": `Bearer ${auth}`},
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiPost<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "POST",
|
||||
headers: {"Authorization": `Bearer ${auth}`, "Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiPut<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "PUT",
|
||||
headers: {"Authorization": `Bearer ${auth}`, "Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiPatch<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "PATCH",
|
||||
headers: {"Authorization": `Bearer ${auth}`, "Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiDelete<T>(url: string, data: object, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "DELETE",
|
||||
headers: {"Authorization": `Bearer ${auth}`, "Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiPostPublic<T>(url: string, data: object, lang: string = "fr"): Promise<T> {
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function apiUpload<T>(url: string, file: File, auth: string, lang: string = "fr"): Promise<T> {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
const response = await fetch(buildUrl(url, {}, lang), {
|
||||
method: "POST",
|
||||
headers: {"Authorization": `Bearer ${auth}`},
|
||||
body: formData,
|
||||
});
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface Configs {
|
||||
appVersion: string;
|
||||
}
|
||||
|
||||
const isProduction: boolean = false;
|
||||
const isProduction: boolean = true;
|
||||
export const isDesktop: boolean = true;
|
||||
|
||||
export const configs: Configs = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import axios from 'axios';
|
||||
import {fetch} from '@tauri-apps/plugin-http';
|
||||
import {configs, isDesktop} from '@/lib/configs';
|
||||
|
||||
interface CrashReportPayload {
|
||||
@@ -49,9 +49,10 @@ function getUserId(): string | undefined {
|
||||
|
||||
async function sendCrashReport(payload: CrashReportPayload): Promise<void> {
|
||||
try {
|
||||
await axios.post(configs.apiUrl + 'crash-report', payload, {
|
||||
await fetch(configs.apiUrl + 'crash-report', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
timeout: 5000,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
} catch {
|
||||
// Silently fail — we can't crash while reporting a crash
|
||||
|
||||
@@ -280,7 +280,6 @@
|
||||
"emptyDescription": "Search for ideas to enrich your writing. Enter a prompt and let AI inspire you with creative suggestions based on your current content.",
|
||||
"emptyPromptError": "Please enter a prompt to get inspired.",
|
||||
"error": {
|
||||
"contentRetrieval": "Error retrieving content.",
|
||||
"contentRetrievalUnknown": "Unknown error retrieving content.",
|
||||
"noBook": "No book selected.",
|
||||
"noChapter": "No chapter selected.",
|
||||
@@ -669,7 +668,6 @@
|
||||
"successSaveAdvanced": "Advanced settings saved successfully.",
|
||||
"errorSave": "An error occurred during saving.",
|
||||
"errorUnknownSave": "An unknown error occurred during saving.",
|
||||
"errorRetrieveContent": "Error retrieving content.",
|
||||
"errorUnknownRetrieveContent": "Unknown error retrieving content.",
|
||||
"abortSuccess": "Generation stopped. Token and cost totals will be available on next page refresh.",
|
||||
"settings": {
|
||||
@@ -1286,7 +1284,6 @@
|
||||
"emailLength": "Email address must be between 5 and 100 characters.",
|
||||
"emailInvalidChars": "Email address contains invalid characters.",
|
||||
"connection": "Connection error. Check your credentials.",
|
||||
"server": "Server error. Please try again later.",
|
||||
"unknown": "An unknown error occurred."
|
||||
}
|
||||
},
|
||||
@@ -1402,11 +1399,8 @@
|
||||
"error": {
|
||||
"emailInvalid": "Please enter a valid email address.",
|
||||
"emailFormat": "The email address format is invalid.",
|
||||
"emailServer": "Server error while verifying email.",
|
||||
"emailUnknown": "An unknown error occurred.",
|
||||
"codeServer": "Server error while verifying code.",
|
||||
"codeUnknown": "An unknown error occurred.",
|
||||
"passwordServer": "Server error while changing password.",
|
||||
"passwordUnknown": "An unknown error occurred."
|
||||
}
|
||||
},
|
||||
|
||||
@@ -280,7 +280,6 @@
|
||||
"emptyDescription": "Recherchez des idées pour enrichir votre écriture. Entrez un prompt et laissez l'IA vous inspirer avec des suggestions créatives basées sur votre contenu actuel.",
|
||||
"emptyPromptError": "Veuillez entrer un prompt pour vous inspirer.",
|
||||
"error": {
|
||||
"contentRetrieval": "Erreur lors de la récupération du contenu.",
|
||||
"contentRetrievalUnknown": "Erreur inconnue lors de la récupération du contenu.",
|
||||
"noBook": "Aucun livre sélectionné.",
|
||||
"noChapter": "Aucun chapitre sélectionné.",
|
||||
@@ -669,7 +668,6 @@
|
||||
"successSaveAdvanced": "Paramètres avancés sauvegardés avec succès.",
|
||||
"errorSave": "Une erreur est survenue pendant la sauvegarde.",
|
||||
"errorUnknownSave": "Une erreur inconnue est survenue pendant la sauvegarde.",
|
||||
"errorRetrieveContent": "Erreur lors de la récupération du contenu.",
|
||||
"errorUnknownRetrieveContent": "Erreur inconnue lors de la récupération du contenu.",
|
||||
"abortSuccess": "Génération arrêtée. Les totaux de tokens et coûts seront disponibles au prochain rafraîchissement de la page.",
|
||||
"settings": {
|
||||
@@ -1285,7 +1283,6 @@
|
||||
"emailLength": "L'adresse e-mail doit contenir entre 5 et 100 caractères.",
|
||||
"emailInvalidChars": "L'adresse e-mail contient des caractères invalides.",
|
||||
"connection": "Erreur de connexion. Vérifiez vos identifiants.",
|
||||
"server": "Erreur du serveur. Veuillez réessayer plus tard.",
|
||||
"unknown": "Une erreur inconnue est survenue."
|
||||
}
|
||||
},
|
||||
@@ -1401,11 +1398,8 @@
|
||||
"error": {
|
||||
"emailInvalid": "Veuillez entrer une adresse e-mail valide.",
|
||||
"emailFormat": "Le format de l'adresse e-mail est invalide.",
|
||||
"emailServer": "Erreur du serveur lors de la vérification de l'e-mail.",
|
||||
"emailUnknown": "Une erreur inconnue est survenue.",
|
||||
"codeServer": "Erreur du serveur lors de la vérification du code.",
|
||||
"codeUnknown": "Une erreur inconnue est survenue.",
|
||||
"passwordServer": "Erreur du serveur lors du changement de mot de passe.",
|
||||
"passwordUnknown": "Une erreur inconnue est survenue."
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user