-
Notifications
You must be signed in to change notification settings - Fork 0
/
beginSync.mjs
36 lines (29 loc) · 1.24 KB
/
beginSync.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Azure from '@azure/storage-blob';
import getContainers from './getContainers.mjs';
import processContainer from './processContainer.mjs';
import debug from 'debug';
const debugController = debug('Controller');
const debugDirectory = debug('Directory');
export default async function beginSync({ storageAccountName, storageAccountKey, storeDirectory }) {
const sharedKeyCredential = new Azure.SharedKeyCredential(storageAccountName, storageAccountKey);
const pipeline = Azure.StorageURL.newPipeline(sharedKeyCredential);
const serviceURL = new Azure.ServiceURL(
`https://${storageAccountName}.blob.core.windows.net`,
pipeline
);
const containers = await getContainers(serviceURL);
for (const container of containers) {
if (container.name === '$root') {
debugController('Skipping root container.');
continue;
}
try {
debugDirectory(`Starting ${container.name}.`);
await processContainer(container, storeDirectory, storageAccountName, serviceURL);
debugDirectory(`Finished ${container.name}.`);
} catch (ex) {
debugDirectory(`Failed ${container.name}`, ex);
}
}
debugController('All finished.');
}