mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
chore: organize ts types, fix eslint errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use server"
|
||||
|
||||
import { ActionState } from "@/lib/actions"
|
||||
import { getCurrentUser } from "@/lib/auth"
|
||||
import { prisma } from "@/lib/db"
|
||||
import { getUserUploadsDirectory } from "@/lib/files"
|
||||
@@ -12,7 +13,14 @@ const SUPPORTED_BACKUP_VERSIONS = ["1.0"]
|
||||
const REMOVE_EXISTING_DATA = true
|
||||
const MAX_BACKUP_SIZE = 256 * 1024 * 1024 // 256MB
|
||||
|
||||
export async function restoreBackupAction(prevState: any, formData: FormData) {
|
||||
type BackupRestoreResult = {
|
||||
counters: Record<string, number>
|
||||
}
|
||||
|
||||
export async function restoreBackupAction(
|
||||
_prevState: ActionState<BackupRestoreResult> | null,
|
||||
formData: FormData
|
||||
): Promise<ActionState<BackupRestoreResult>> {
|
||||
const user = await getCurrentUser()
|
||||
const userUploadsDirectory = await getUserUploadsDirectory(user)
|
||||
const file = formData.get("file") as File
|
||||
@@ -32,7 +40,7 @@ export async function restoreBackupAction(prevState: any, formData: FormData) {
|
||||
const fileData = Buffer.from(fileBuffer)
|
||||
zip = await JSZip.loadAsync(fileData)
|
||||
} catch (error) {
|
||||
return { success: false, error: "Bad zip archive" }
|
||||
return { success: false, error: "Bad zip archive: " + (error as Error).message }
|
||||
}
|
||||
|
||||
// Check metadata and start restoring
|
||||
@@ -133,7 +141,7 @@ export async function restoreBackupAction(prevState: any, formData: FormData) {
|
||||
}
|
||||
}
|
||||
|
||||
return { success: true, message: "Restore completed successfully", counters }
|
||||
return { success: true, data: { counters } }
|
||||
} catch (error) {
|
||||
console.error("Error restoring from backup:", error)
|
||||
return {
|
||||
|
||||
@@ -9,7 +9,7 @@ import path from "path"
|
||||
const MAX_FILE_SIZE = 64 * 1024 * 1024 // 64MB
|
||||
const BACKUP_VERSION = "1.0"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
export async function GET() {
|
||||
const user = await getCurrentUser()
|
||||
const userUploadsDirectory = await getUserUploadsDirectory(user)
|
||||
|
||||
@@ -87,7 +87,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
async function getAllFilePaths(dirPath: string): Promise<string[]> {
|
||||
let filePaths: string[] = []
|
||||
const filePaths: string[] = []
|
||||
|
||||
async function readDirectoryRecursively(currentPath: string) {
|
||||
const isDirExists = await fileExists(currentPath)
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function BackupSettingsPage() {
|
||||
<h2 className="text-xl font-semibold">Backup restored successfully</h2>
|
||||
<p className="text-sm text-muted-foreground">You can now continue using the app. Import stats:</p>
|
||||
<ul className="list-disc list-inside">
|
||||
{Object.entries(restoreState.counters || {}).map(([key, value]) => (
|
||||
{Object.entries(restoreState.data?.counters || {}).map(([key, value]) => (
|
||||
<li key={key}>
|
||||
<span className="font-bold">{key}</span>: {value} items
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user