* fix: remove circular dependency redux depended on templates/Challenges/redux and vice versa. This meant that import order mattered and confusing bugs could arise. (cherry picked from commit 7d67a4e70922bbb3051f2f9982dcc69e240d43dc) * feat: require imports to be in alphabetical order Import order generally does not matter, but there are edge cases (circular imports and css imports, for example) where changing order changes behaviour (cherry picked from commit b8d1393a91ec6e068caf8e8498a5c95df68c2b2c) * chore: order imports * fix: lift up challenge description + title comps This brings the classic Show closer to the others as they now all create the description and title components * fix: remove donation-saga/index circular import (cherry picked from commit 51a44ca668a700786d2744feffeae4fdba5fd207) * refactor: extract action-types from settings (cherry picked from commit 25e26124d691c84a0d0827d41dafb761c686fadd) * fix: lint errors * feat: prevent useless renames
87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
const authHeader = require('./auth-header');
|
|
const delay = require('./delay');
|
|
const makeRequest = require('./make-request');
|
|
|
|
const getDirs = async projectId => {
|
|
let headers = { ...authHeader };
|
|
let done = false;
|
|
let offset = 0;
|
|
let files = [];
|
|
while (!done) {
|
|
const endPoint = `projects/${projectId}/directories?limit=500&offset=${offset}`;
|
|
await delay(1000);
|
|
const response = await makeRequest({
|
|
method: 'get',
|
|
endPoint,
|
|
headers
|
|
});
|
|
if (response.data) {
|
|
if (response.data.length) {
|
|
files = [...files, ...response.data];
|
|
offset += 500;
|
|
} else {
|
|
done = true;
|
|
return files;
|
|
}
|
|
} else {
|
|
const { error } = response;
|
|
console.log(error.errorcode);
|
|
console.log(error.messsage);
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
|
|
const addDir = async (projectId, dirName, parentDirId) => {
|
|
let headers = { ...authHeader };
|
|
const endPoint = `projects/${projectId}/directories`;
|
|
let body = {
|
|
name: dirName
|
|
};
|
|
if (parentDirId) {
|
|
body = { ...body, directoryId: parentDirId };
|
|
}
|
|
|
|
const response = await makeRequest({
|
|
method: 'post',
|
|
endPoint,
|
|
headers,
|
|
body
|
|
});
|
|
return response;
|
|
};
|
|
|
|
const createDirs = async (crowdinDirs, dirPath) => {
|
|
// superParent is the top level directory on crowdin
|
|
const superParent = crowdinDirs.find(dir => !dir.data.directoryId);
|
|
let lastParentId = superParent.data.id;
|
|
|
|
const splitDirPath = dirPath.split('/');
|
|
splitDirPath.shift();
|
|
|
|
// we are assuming that the first directory in 'newFile' is the same as the superParent
|
|
// maybe throw a check in here to verify that's true
|
|
const findCurrDir = (directory, crowdinDirs) => {
|
|
return crowdinDirs.find(({ data: { name, directoryId } }) => {
|
|
return name === directory && directoryId === lastParentId;
|
|
});
|
|
};
|
|
|
|
for (let directory of splitDirPath) {
|
|
const currentDirectory = findCurrDir(directory, crowdinDirs);
|
|
if (!currentDirectory) {
|
|
const response = await addDir(10, directory, lastParentId);
|
|
lastParentId = response.data.id;
|
|
} else {
|
|
lastParentId = currentDirectory.data.id;
|
|
}
|
|
}
|
|
return lastParentId;
|
|
};
|
|
|
|
module.exports = {
|
|
addDir,
|
|
getDirs,
|
|
createDirs
|
|
};
|