mirror of
https://github.com/GenderDysphoria/GenderDysphoria.fyi.git
synced 2025-11-25 20:42:40 +00:00
Pulled in the twitter content backup functionality from curvyandtrans.com
Sadly, lost the images from one of Emmy_Zje's deleted tweets.
This commit is contained in:
@@ -72,10 +72,10 @@ module.exports = exports = class Manifest {
|
||||
|
||||
async get (task) {
|
||||
const hash = this.hash(task);
|
||||
const { input, output } = task;
|
||||
const { input, output, cache: altCachePath } = task;
|
||||
const ext = path.extname(task.output);
|
||||
const local = !task.input.includes('://');
|
||||
const cached = path.join(CACHE, hash + ext);
|
||||
var cached = path.join(CACHE, hash + ext);
|
||||
const result = {
|
||||
iTime: 0,
|
||||
iRev: null,
|
||||
@@ -85,9 +85,15 @@ module.exports = exports = class Manifest {
|
||||
action: task.action.name,
|
||||
input,
|
||||
output,
|
||||
duplicate: altCachePath,
|
||||
mode: 'new',
|
||||
};
|
||||
|
||||
var acTime;
|
||||
if (altCachePath) {
|
||||
acTime = await this.stat(altCachePath);
|
||||
}
|
||||
|
||||
const [ iTime, oTime, cTime, iRev ] = await Promise.all([
|
||||
local && this.stat(input),
|
||||
this.stat(output),
|
||||
@@ -148,7 +154,17 @@ module.exports = exports = class Manifest {
|
||||
}
|
||||
|
||||
result.mode = 'cached';
|
||||
result.cache = await readFile(cached);
|
||||
|
||||
if (acTime && acTime > cTime) {
|
||||
result.cache = await readFile(altCachePath);
|
||||
} else {
|
||||
result.cache = await readFile(cached);
|
||||
if (altCachePath && !acTime) {
|
||||
await fs.ensureDir(resolve(path.dirname(altCachePath)));
|
||||
await fs.writeFile(resolve(altCachePath), result.cache);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -157,7 +173,7 @@ module.exports = exports = class Manifest {
|
||||
if (task.nocache || !task.action.name) return null;
|
||||
|
||||
const hash = this.hash(task);
|
||||
const { input, output } = task;
|
||||
const { input, output, cache: altCachePath } = task;
|
||||
const local = !task.input.includes('://');
|
||||
|
||||
const [ iTime, iRev ] = await Promise.all([
|
||||
@@ -175,6 +191,7 @@ module.exports = exports = class Manifest {
|
||||
output,
|
||||
oTime: Math.floor(lastSeen / 1000),
|
||||
lastSeen,
|
||||
duplicate: altCachePath,
|
||||
};
|
||||
|
||||
if (record.revPath) this.revManifest[output] = record.revPath;
|
||||
@@ -185,17 +202,22 @@ module.exports = exports = class Manifest {
|
||||
|
||||
async set (task, result, lastSeen = new Date()) {
|
||||
const hash = this.hash(task);
|
||||
const { input, output } = task;
|
||||
const { input, output, cache: altCachePath } = task;
|
||||
const nocache = task.nocache || task.action.name === 'copy';
|
||||
const ext = path.extname(task.output);
|
||||
const local = !task.input.includes('://');
|
||||
const cached = path.join(CACHE, hash + ext);
|
||||
const oRev = revHash(result);
|
||||
|
||||
if (result && altCachePath) {
|
||||
await fs.ensureDir(resolve(path.dirname(altCachePath)));
|
||||
}
|
||||
|
||||
const [ iTime, iRev ] = await Promise.all([
|
||||
local && this.stat(input),
|
||||
local && this.compareBy.inputRev && this.revFile(input),
|
||||
result && !nocache && fs.writeFile(resolve(cached), result),
|
||||
result && altCachePath && fs.writeFile(resolve(altCachePath), result),
|
||||
]);
|
||||
|
||||
const record = {
|
||||
@@ -208,6 +230,7 @@ module.exports = exports = class Manifest {
|
||||
oTime: Math.floor(lastSeen / 1000),
|
||||
oRev,
|
||||
lastSeen,
|
||||
duplicate: altCachePath,
|
||||
revPath: revPath(output, oRev),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user