Search.../

listDeletedFolders( )

Developer Preview

Retrieves a list of deleted folders from the trash bin.

Description

The listDeletedFolders() function returns a Promise that resolves to information about the specified deleted folders and cursor information.

To retrieve a list of non-deleted folders, use the listFolders() function.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listDeletedFolders(options: ListDeletedFoldersOptions): Promise<ListDeletedFoldersResponse>

listDeletedFolders Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListDeletedFoldersOptions

Options to use when listing deleted folders from the trash bin.

Returns

Return Type:

Promise<
ListDeletedFoldersResponse
>
NAME
TYPE
DESCRIPTION
folders
Array<
Folder
>

List of folders in the Media Manager's trash bin.

nextCursor
PagingMetadataV2

The next cursor if it exists.

Was this helpful?

List deleted folders

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4async function listDeletedFolders() {
5 try {
6 const elevatedListDeletedFolders = elevate(folders.listDeletedFolders);
7 const deletedFolders = await elevatedListDeletedFolders();
8
9 console.log("Deleted Folders:", deletedFolders);
10 return deletedFolders;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15}
16
17/* Promise resolves to:
18 * {
19 * "folders": [
20 * {
21 * "_createdDate": "2023-08-21T09:32:47.000Z",
22 * "_id": "d4051a6890724365a78678a6208ac37e",
23 * "_updatedDate": "2023-08-21T09:32:47.000Z",
24 * "displayName": "family",
25 * "parentFolderId": "trash-root",
26 * "state": "DELETED"
27 * },
28 * {
29 * "_createdDate": "2023-08-21T05:34:03.000Z",
30 * "_id": "302fc049d70c41dea33fa4a27ab481ba",
31 * "_updatedDate": "2023-08-21T05:34:03.000Z",
32 * "displayName": "Videos",
33 * "parentFolderId": "trash-root",
34 * "state": "DELETED"
35 * }
36 * ],
37 * "nextCursor": {
38 * "cursors": {
39 * "next": ""
40 * },
41 * "hasNext": false
42 * }
43 * }
44 */
List deleted folders with sort

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample options value:
5 * {
6 * sort: {
7 * fieldName: 'displayName',
8 * order: 'ASC'
9 * }
10 * }
11 */
12
13async function listDeletedFolders(options) {
14 try {
15 const elevatedListDeletedFolders = elevate(folders.listDeletedFolders);
16 const deletedFolders = await elevatedListDeletedFolders(options);
17
18 console.log("Deleted folders, sorted alphabetically by name:", deletedFolders);
19 return deletedFolders;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "folders": [
29 * {
30 * "_createdDate": "2023-08-21T05:34:03.000Z",
31 * "_id": "302fc049d70c41dea33fa4a27ab481ba",
32 * "_updatedDate": "2023-08-21T05:34:03.000Z",
33 * "displayName": "Videos",
34 * "parentFolderId": "trash-root",
35 * "state": "DELETED"
36 * },
37 * {
38 * "_createdDate": "2023-08-21T09:32:47.000Z",
39 * "_id": "d4051a6890724365a78678a6208ac37e",
40 * "_updatedDate": "2023-08-21T09:32:47.000Z",
41 * "displayName": "family",
42 * "parentFolderId": "trash-root",
43 * "state": "DELETED"
44 * }
45 * ],
46 * "nextCursor": {
47 * "cursors": {
48 * "next": ""
49 * },
50 * "hasNext": false
51 * }
52 * }
53 */
Bulk restore all folders from the trash bin

Copy Code
1/**************************************
2 * Backend code - restore-folders.jsw *
3 *************************************/
4
5import { folders } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8async function restoreAllFolders() {
9 try {
10 const elevatedListDeletedFolders = elevate(folders.listDeletedFolders);
11 const deletedFolders = await elevatedListDeletedFolders();
12
13 const deletedFolderIds = deletedFolders.map((folder) => {
14 return folder._id;
15 });
16
17 const elevatedBulkRestoreFoldersFromTrashBin = elevate(folders.bulkRestoreFoldersFromTrashBin);
18 const restoredFolders = await elevatedBulkRestoreFoldersFromTrashBin(deletedFolderIds);
19
20 return restoredFolders;
21 } catch (error) {
22 console.error(error);
23 }
24}
25
26
27/*************
28 * Page code *
29 ************/
30
31import { restoreAllFolders } from 'backend/restore-folders';
32
33$w.onReady(async () => {
34 $w('#restoreAll').onClick(async () => {
35 const restoredFolders = await restoreAllFolders();
36
37 console.log('Restored all folders:', restoredFolders);
38 $w('#bulkRestoreSuccessMsg').show();
39 });
40});
41