-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added restore file functionality
- Loading branch information
1 parent
de07e3d
commit 79de675
Showing
5 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use server'; | ||
|
||
import { connectToFTP } from './connect'; | ||
|
||
export async function getRecentlyDeletedFiles(loc: string) { | ||
const client = await connectToFTP(loc); | ||
try { | ||
await client.cd('trash'); | ||
const files = await client.list(); | ||
const filesData = | ||
files?.map((file) => ({ | ||
name: file.name, | ||
size: file.size, | ||
modifiedAt: file.modifiedAt, | ||
})) ?? []; | ||
return filesData; | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} finally { | ||
client.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use server'; | ||
|
||
import { connectToFTP } from './connect'; | ||
|
||
export async function restoreFile({ | ||
filename, | ||
loc, | ||
}: { | ||
filename: string; | ||
loc: string; | ||
}) { | ||
const client = await connectToFTP(loc); | ||
try { | ||
await client.rename(`/trash/${filename}`, `/${filename}`); | ||
console.log(`File ${filename} restored successfully.`); | ||
} catch (e) { | ||
const errorMsg = (e as { message: string })?.message || ''; | ||
console.error('Error restoring file:', e); | ||
throw new Error(`Failed to restore file: ${errorMsg}`); | ||
} finally { | ||
client.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters