mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-24 17:07:31 +00:00
New constants/config merge system
This commit is contained in:
parent
fb6081a719
commit
cf8fd6b86b
@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
Welcome to the config file!
|
||||||
|
Add keys here to override values from /src/lib/constants.js. Please look at that file for override recommendations.
|
||||||
|
This file should hopefully never be altered upstream.
|
||||||
|
You must restart Bibliogram to apply these changes.
|
||||||
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
website_origin: "http://localhost:10407"
|
|
||||||
}
|
}
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -868,6 +868,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
},
|
},
|
||||||
|
"mixin-deep": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA=="
|
||||||
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gm": "^1.23.1",
|
"gm": "^1.23.1",
|
||||||
|
"mixin-deep": "^2.0.1",
|
||||||
"node-dir": "^0.1.17",
|
"node-dir": "^0.1.17",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"pinski": "github:cloudrac3r/pinski#19495f7a1c62fbfd8c685cf5bb5d678788906032",
|
"pinski": "github:cloudrac3r/pinski#19495f7a1c62fbfd8c685cf5bb5d678788906032",
|
||||||
|
@ -4,9 +4,9 @@ const {extractSharedData} = require("./utils/body")
|
|||||||
const {TtlCache, RequestCache} = require("./cache")
|
const {TtlCache, RequestCache} = require("./cache")
|
||||||
require("./testimports")(constants, request, extractSharedData, RequestCache)
|
require("./testimports")(constants, request, extractSharedData, RequestCache)
|
||||||
|
|
||||||
const requestCache = new RequestCache(constants.resource_cache_time)
|
const requestCache = new RequestCache(constants.caching.resource_cache_time)
|
||||||
/** @type {import("./cache").TtlCache<import("./structures/TimelineEntry")>} */
|
/** @type {import("./cache").TtlCache<import("./structures/TimelineEntry")>} */
|
||||||
const timelineEntryCache = new TtlCache(constants.resource_cache_time)
|
const timelineEntryCache = new TtlCache(constants.caching.resource_cache_time)
|
||||||
|
|
||||||
function fetchUser(username) {
|
function fetchUser(username) {
|
||||||
return requestCache.getOrFetch("user/"+username, () => {
|
return requestCache.getOrFetch("user/"+username, () => {
|
||||||
@ -39,6 +39,7 @@ function fetchTimelinePage(userID, after) {
|
|||||||
}))
|
}))
|
||||||
return requestCache.getOrFetchPromise("page/"+after, () => {
|
return requestCache.getOrFetchPromise("page/"+after, () => {
|
||||||
return request(`https://www.instagram.com/graphql/query/?${p.toString()}`).then(res => res.json()).then(root => {
|
return request(`https://www.instagram.com/graphql/query/?${p.toString()}`).then(res => res.json()).then(root => {
|
||||||
|
if (!root.data) console.error("missing data:", root) //todo: please make this better.
|
||||||
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
|
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
|
||||||
const timeline = root.data.user.edge_owner_to_timeline_media
|
const timeline = root.data.user.edge_owner_to_timeline_media
|
||||||
return timeline
|
return timeline
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
module.exports = {
|
/*
|
||||||
image_cache_control: `public, max-age=${7*24*60*60}`,
|
Welcome to the constants file!
|
||||||
resource_cache_time: 30*60*1000,
|
Copy a key and provide a new value in /config.js to override the value here.
|
||||||
|
Please read the comments above every section!
|
||||||
|
*/
|
||||||
|
|
||||||
|
let constants = {
|
||||||
|
// Things that server owners _should_ change!
|
||||||
|
website_origin: "http://localhost:10407",
|
||||||
|
|
||||||
|
// Things that server owners _could_ change if they want to.
|
||||||
|
caching: {
|
||||||
|
image_cache_control: `public, max-age=${7*24*60*60}`,
|
||||||
|
resource_cache_time: 30*60*1000
|
||||||
|
},
|
||||||
|
|
||||||
|
// Instagram uses this stuff. This shouldn't be changed, except to fix a bug that hasn't yet been fixed upstream.
|
||||||
external: {
|
external: {
|
||||||
timeline_query_hash: "e769aa130647d2354c40ea6a439bfc08",
|
timeline_query_hash: "e769aa130647d2354c40ea6a439bfc08",
|
||||||
shortcode_query_hash: "2b0673e0dc4580674a88d426fe00ea90",
|
shortcode_query_hash: "2b0673e0dc4580674a88d426fe00ea90",
|
||||||
@ -10,6 +23,7 @@ module.exports = {
|
|||||||
shortcode_regex: "[\\w-]+"
|
shortcode_regex: "[\\w-]+"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// My code uses this stuff. Server owners have no reason to change it.
|
||||||
symbols: {
|
symbols: {
|
||||||
NO_MORE_PAGES: Symbol("NO_MORE_PAGES"),
|
NO_MORE_PAGES: Symbol("NO_MORE_PAGES"),
|
||||||
TYPE_IMAGE: Symbol("TYPE_IMAGE"),
|
TYPE_IMAGE: Symbol("TYPE_IMAGE"),
|
||||||
@ -21,3 +35,9 @@ module.exports = {
|
|||||||
NO_SHARED_DATA: Symbol("NO_SHARED_DATA")
|
NO_SHARED_DATA: Symbol("NO_SHARED_DATA")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override values from config and export the result
|
||||||
|
const md = require("mixin-deep")
|
||||||
|
const config = require("../../config")
|
||||||
|
constants = md(constants, config)
|
||||||
|
module.exports = constants
|
||||||
|
@ -18,7 +18,7 @@ class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTtl(scale = 1) {
|
getTtl(scale = 1) {
|
||||||
const expiresAt = this.cachedAt + constants.resource_cache_time
|
const expiresAt = this.cachedAt + constants.caching.resource_cache_time
|
||||||
const ttl = expiresAt - Date.now()
|
const ttl = expiresAt - Date.now()
|
||||||
return Math.ceil(Math.max(ttl, 0) / scale)
|
return Math.ceil(Math.max(ttl, 0) / scale)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ module.exports = [
|
|||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
contentType: "image/jpeg",
|
contentType: "image/jpeg",
|
||||||
headers: {
|
headers: {
|
||||||
"Cache-Control": constants.image_cache_control
|
"Cache-Control": constants.caching.image_cache_control
|
||||||
},
|
},
|
||||||
stream: image.stream("jpg")
|
stream: image.stream("jpg")
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ module.exports = [
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return proxy(url, {
|
return proxy(url, {
|
||||||
"Cache-Control": constants.image_cache_control
|
"Cache-Control": constants.caching.image_cache_control
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const {instance, pugCache, wss} = require("./passthrough")
|
const {instance, pugCache, wss} = require("./passthrough")
|
||||||
const {requestCache, timelineEntryCache} = require("../lib/collectors")
|
const {requestCache, timelineEntryCache} = require("../lib/collectors")
|
||||||
|
const constants = require("../lib/constants")
|
||||||
const util = require("util")
|
const util = require("util")
|
||||||
const repl = require("repl")
|
const repl = require("repl")
|
||||||
const vm = require("vm")
|
const vm = require("vm")
|
||||||
|
Loading…
Reference in New Issue
Block a user