나만 쓰려고 만든 코드. 백업용


(async (urls) => {

    const dhandle = await showDirectoryPicker({ mode: 'readwrite' });


    console.group('download');

    await urls.reduce(async (acc, cur, idx) => {

        const result = await acc;


        try {

            console.log(`${idx + 1} / ${urls.length} downloading`, cur);

            const res = await fetch(cur);


            if (!res.ok) throw res;

            

            const blob = await res.blob();

            

            const fhandle = await dhandle.getFileHandle(new URL(cur).pathname.split('/').at(-1), { create: true });

            const writable = await fhandle.createWritable();

            

            try {

                await writable.write(blob);

            } catch (e) {

                console.error('write error', e);

            } finally {

                writable.close();

            }

        } catch (e) {

            console.error('download error', e);

        }


        return result;

    }, Promise.resolve([]));

    console.log('download completed!');

    console.groupEnd('download');

})([...document.querySelectorAll('figure.fileblock > a')].map(a => a.href));