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

Fix filemanger fetch error #387

Merged
merged 2 commits into from
Nov 13, 2020
Merged
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
34 changes: 13 additions & 21 deletions packages/cms-lib/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,14 @@ async function downloadFile(accountId, file, dest, options) {
return;
}

const logFsError = err => {
logFileSystemErrorInstance(
err,
new FileSystemErrorContext({
destPath,
accountId,
write: true,
})
);
};
let writeStream;

try {
await fs.ensureFile(destPath);
writeStream = fs.createWriteStream(destPath, { encoding: 'binary' });
} catch (err) {
logFsError(err);
throw err;
}

try {
await http.getOctetStream(
accountId,
{
baseUrl: file.url,
uri: '',
},
writeStream
destPath
);
logger.log(`Wrote file "${destPath}"`);
} catch (err) {
Expand Down Expand Up @@ -174,6 +154,18 @@ async function fetchAllPagedFiles(accountId, folderId, { includeArchived }) {
* @param {object} options
*/
async function fetchFolderContents(accountId, folder, dest, options) {
try {
await fs.ensureDir(dest);
} catch (err) {
logFileSystemErrorInstance(
err,
new FileSystemErrorContext({
dest,
accountId,
write: true,
})
);
}
const files = await fetchAllPagedFiles(accountId, folder.id, options);
for (const file of files) {
await downloadFile(accountId, file, dest, options);
Expand Down