Skip to content

Commit

Permalink
WIndows works perfectly
Browse files Browse the repository at this point in the history
  • Loading branch information
o0101 committed Aug 29, 2024
1 parent d91a185 commit dac4145
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/archivist.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
]);
const NEVER_CACHE = new Set([
`${GO_SECURE ? 'https://localhost' : 'http://127.0.0.1'}:${args.server_port}`,
`http://localhost:${args.server_port}`,
`http://localhost:${args.chrome_port}`,
`http://127.0.0.1:${args.chrome_port}`,
`https://127.0.0.1:${args.chrome_port}`,
Expand Down Expand Up @@ -776,29 +777,39 @@
}

async function saveResponseData(key, url, response) {
const origin = (new URL(url).origin);
let originDir = State.Cache.get(origin);
originDir = originDir.replace(TBL, '_');
if ( ! originDir ) {
originDir = Path.resolve(library_path(), origin.replace(TBL, '_'));
try {
const origin = (new URL(url).origin);
let originDir = State.Cache.get(origin);
if ( ! originDir ) {
originDir = Path.resolve(library_path(), origin.replace(TBL, '_'));
try {
Fs.mkdirSync(originDir, {recursive:true});
} catch(e) {
console.warn(`Issue with origin directory ${originDir}`, e);
}
State.Cache.set(origin, originDir);
} else {
if ( originDir.includes(':\\\\') ) {
originDir = originDir.split(/:\\\\/, 2);
originDir[1] = originDir[1]?.replace?.(TBL, '_');
originDir = originDir.join(':\\\\');
}
}

const fileName = `${await sha1(key)}.json`;

const responsePath = Path.resolve(originDir, fileName);
try {
Fs.mkdirSync(originDir, {recursive:true});
await Fs.promises.writeFile(responsePath, JSON.stringify(response,null,2));
} catch(e) {
console.warn(`Issue with origin directory ${originDir}`, e);
console.warn(`Issue with origin directory or file: ${responsePath}`, e);
}
State.Cache.set(origin, originDir);
}

const fileName = `${await sha1(key)}.json`;

const responsePath = Path.resolve(originDir, fileName);
try {
await Fs.promises.writeFile(responsePath, JSON.stringify(response,null,2));
return responsePath;
} catch(e) {
console.warn(`Issue with origin directory or file: ${responsePath}`, e);
console.warn(`Could not save response data`, e);
return '';
}

return responsePath;
}

async function sha1(key) {
Expand Down

0 comments on commit dac4145

Please sign in to comment.