Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port filemanager #75

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions api/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import http from '../http';
import { FormData } from '../types/Http';
import {
FetchStatResponse,
FetchFilesOrFolderResponse,
FetchFilesResponse,
FetchFolderResponse,
UploadResponse,
} from '../types/FileManager';

Expand Down Expand Up @@ -50,10 +51,10 @@ export async function fetchStat(

export async function fetchFiles(
accountId: number,
folderId: number,
folderId: number | 'None',
offset: number,
archived?: boolean
): Promise<FetchFilesOrFolderResponse> {
): Promise<FetchFilesResponse> {
return http.get(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/files/`,
query: {
Expand All @@ -67,8 +68,8 @@ export async function fetchFiles(

export async function fetchFolders(
accountId: number,
folderId: number
): Promise<FetchFilesOrFolderResponse> {
folderId: number | 'None'
): Promise<FetchFolderResponse> {
return http.get(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/folders/`,
query: {
Expand Down
15 changes: 15 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@
"success": "Configuration updated"
}
},
"fileManager": {
"uploadStarted": "Uploading files from \"{{ file }}\" to \"{{ destPath }}\" in the File Manager of account {{ accountId }}",
"uploadSuccess": "Uploaded file \"{{ file }}\" to \"{{ destPath }}\"",
"skippedExisting": "Skipped existing {{ filepath }}",
"fetchingFiles": "Fetching {{ fileCount }} files from remote folder: {{ folderName }}",
"fetchFolderStarted": "Fetching folder from \"{{ src }}\" to \"{{ path }}\" in the File Manager of account {{ accountId }}",
"fetchFolderSuccess": "Completed fetch of folder \"{{ src }}\" to \"{{ dest }}\" from the File Manager",
"fetchFileStarted": "Fetching file from \"{{ src }}\" to \"{{ dest }}\" in the File Manager of account {{ accountId }}",
"fetchFileSuccess": "Completed fetch of file \"{{ src }}\" to \"{{ dest }}\" from the File Manager",
"errors": {
"uploadFailed": "Uploading file \"{{ file }}\" to \"{{ destPath }}\" failed",
"archivedFile": "\"{{ src }} \" in the File Manager is an archived file. Try fetching again with the \"--include-archived\" flag",
"hiddenFile": "\"{{ src }}\" in the File Manager is a hidden file."
}
},
"fileMapper": {
"skippedExisting": "Skipped existing {{ filepath }}",
"wroteFolder": "Wrote folder {{ filepath }}",
Expand Down
43 changes: 43 additions & 0 deletions lib/__tests__/fileManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { uploadFolder } from '../fileManager';
import { uploadFile } from '../../api/fileManager';
import { walk } from '../fs';
import { createIgnoreFilter } from '../ignoreRules';

jest.mock('../fs');
jest.mock('../../api/fileManager');
jest.mock('../ignoreRules');

describe('lib/fileManager', () => {
describe('uploadFolder()', () => {
it('uploads files in the folder', async () => {
const files = [
'folder/document.pdf',
'folder/images/image.png',
'folder/images/image.jpg',
'folder/video/video.mp4',
];

const mockedWalk = jest.mocked(walk);
const mockedUploadFile = jest.mocked(uploadFile);
const mockedCreateIgnoreFilter = jest.mocked(createIgnoreFilter);

mockedWalk.mockResolvedValue(files);
mockedUploadFile.mockImplementation(() =>
Promise.resolve({ objects: [] })
);
mockedCreateIgnoreFilter.mockImplementation(() => () => true);

const accountId = 123;
const src = 'folder';
const dest = 'folder';

await uploadFolder(accountId, src, dest);

expect(uploadFile).toReturnTimes(4);

files.forEach((file, index) => {
expect(uploadFile).nthCalledWith(index + 1, accountId, file, file);
});
});
});
});
Loading
Loading