mirror of https://gitgud.io/fatchan/jschan.git
webring support, optional. currently adds webringed boards to homepage list. in future will move to board list page
parent
7d2acf017c
commit
f7d1ba9470
12 changed files with 206 additions and 72 deletions
@ -0,0 +1,32 @@ |
||||
'use strict'; |
||||
|
||||
const Files = require(__dirname+'/../../db/files.js') |
||||
, { remove } = require('fs-extra') |
||||
, uploadDirectory = require(__dirname+'/uploadDirectory.js'); |
||||
|
||||
module.exports = async() => { |
||||
//todo: make this not a race condition, but it only happens daily so ¯\_(ツ)_/¯
|
||||
const files = await Files.db.aggregate({ |
||||
'count': { |
||||
'$lte': 1 |
||||
} |
||||
}, { |
||||
'projection': { |
||||
'count': 0, |
||||
'size': 0 |
||||
} |
||||
}).toArray().then(res => { |
||||
return res.map(x => x._id); |
||||
}); |
||||
await Files.db.removeMany({ |
||||
'count': { |
||||
'$lte': 0 |
||||
} |
||||
}); |
||||
await Promise.all(files.map(async filename => { |
||||
return Promise.all([ |
||||
remove(`${uploadDirectory}img/${filename}`), |
||||
remove(`${uploadDirectory}img/thumb-${filename.split('.')[0]}.jpg`) |
||||
]) |
||||
})); |
||||
} |
@ -0,0 +1,60 @@ |
||||
'use strict'; |
||||
|
||||
const fetch = require('node-fetch') |
||||
, { meta } = require(__dirname+'/configs/main.json') |
||||
, { following, blacklist } = require(__dirname+'/configs/webring.json') |
||||
, { Boards } = require(__dirname+'/db/') |
||||
, { outputFile } = require('fs-extra') |
||||
, cache = require(__dirname+'/redis.js') |
||||
, uploadDirectory = require(__dirname+'/helpers/files/uploadDirectory.js'); |
||||
|
||||
module.exports = async () => { |
||||
//fetch stuff from others
|
||||
const fetchWebring = [...new Set((await cache.get('webring:sites') || []).concat(following))] |
||||
let rings = await Promise.all(fetchWebring.map(url => { |
||||
return fetch(url).then(res => res.json()); |
||||
})); |
||||
let found = []; |
||||
let webringBoards = []; |
||||
for (let i = 0; i < rings.length; i++) { |
||||
//this could really use some validation/sanity checking
|
||||
const ring = rings[i]; |
||||
if (ring.following && ring.following.length > 0) { |
||||
found = found.concat(ring.following); |
||||
} |
||||
if (ring.known && ring.known.length > 0) { |
||||
found = found.concat(ring.known); |
||||
} |
||||
if (ring.boards && ring.boards.length > 0) { |
||||
ring.boards.forEach(board => board.siteName = ring.name); |
||||
webringBoards = webringBoards.concat(ring.boards); |
||||
} |
||||
} |
||||
const known = [...new Set(found.concat(fetchWebring))] |
||||
.filter(site => !blacklist.some(x => site.includes(x))); |
||||
//add the known sites and boards to cache in redis (so can be used later in other places e.g. board list)
|
||||
cache.set('webring:sites', known); |
||||
cache.set('webring:boards', webringBoards); |
||||
//now update the webring json with board list and known sites
|
||||
const boards = await Boards.boardSort(0, 0); //does not include unlisted boards
|
||||
const json = { |
||||
name: meta.siteName, |
||||
url: meta.url, |
||||
endpoint: `${meta.url}/webring.json`, |
||||
following, |
||||
blacklist, |
||||
known, |
||||
boards: boards.map(b => { |
||||
return { |
||||
uri: b._id, |
||||
title: b.settings.name, |
||||
subtitle: b.settings.description, |
||||
path: `${meta.url}/${b._id}/`, |
||||
postsPerHour: b.pph, |
||||
totalPosts: b.sequence_value-1, |
||||
uniqueUsers: b.ips, |
||||
}; |
||||
}), |
||||
} |
||||
await outputFile(`${uploadDirectory}json/webring.json`, JSON.stringify(json)); |
||||
} |
Loading…
Reference in new issue