mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-16 21:27:30 +00:00
Save proxied media with shortcode as filename
This commit is contained in:
parent
7237ebf8d4
commit
48c6e4a8a6
@ -27,13 +27,13 @@ class TimelineBaseMethods {
|
||||
|
||||
getDisplayUrlP() {
|
||||
let url = this.data.display_url
|
||||
if (constants.proxy_media.image) url = proxyImage(url)
|
||||
if (constants.proxy_media.image) url = proxyImage(url, null, this.data.shortcode)
|
||||
return url
|
||||
}
|
||||
|
||||
getVideoUrlP() {
|
||||
let url = this.data.video_url
|
||||
if (constants.proxy_media.video) url = proxyVideo(url)
|
||||
if (constants.proxy_media.video) url = proxyVideo(url, this.data.shortcode)
|
||||
return url
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
if (this.data.thumbnail_resources) {
|
||||
return this.data.thumbnail_resources.map(tr => {
|
||||
let src = tr.src
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(tr.src, tr.config_width)
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(tr.src, tr.config_width, this.data.shortcode)
|
||||
return `${src} ${tr.config_width}w`
|
||||
}).join(", ")
|
||||
} else {
|
||||
@ -195,7 +195,7 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
if (tr.config_width >= size) break // don't proceed once we find one large enough
|
||||
}
|
||||
let src = found.src
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(src, found.config_width) // force resize to config rather than requested
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(src, found.config_width, this.data.shortcode) // force resize to config rather than requested
|
||||
return {
|
||||
config_width: found.config_width,
|
||||
config_height: found.config_height,
|
||||
@ -203,7 +203,7 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
}
|
||||
} else if (this.data.thumbnail_src) {
|
||||
let src = this.data.thumbnail_src
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(src, size) // force resize to requested
|
||||
if (constants.proxy_media.thumbnail) src = proxyImage(src, size, this.data.shortcode) // force resize to requested
|
||||
return {
|
||||
config_width: size, // probably?
|
||||
config_height: size,
|
||||
|
@ -26,11 +26,12 @@ function verifyURL(completeURL) {
|
||||
return {status: "ok", url}
|
||||
}
|
||||
|
||||
function proxyImage(url, width) {
|
||||
function proxyImage(url, width, shortcode) {
|
||||
shortcode = shortcode ? `/${shortcode}${width ? "-small" : ""}.jpg` : ""
|
||||
const params = new URLSearchParams()
|
||||
if (width) params.set("width", width)
|
||||
params.set("url", url)
|
||||
return "/imageproxy?"+params.toString()
|
||||
return `/imageproxy${shortcode}?${params.toString()}`
|
||||
}
|
||||
|
||||
function proxyProfilePic(url, userID) {
|
||||
@ -40,10 +41,11 @@ function proxyProfilePic(url, userID) {
|
||||
return "/imageproxy?"+params.toString()
|
||||
}
|
||||
|
||||
function proxyVideo(url) {
|
||||
function proxyVideo(url, shortcode) {
|
||||
shortcode = shortcode ? `/${shortcode}.jpg` : ""
|
||||
const params = new URLSearchParams()
|
||||
params.set("url", url)
|
||||
return "/videoproxy?"+params.toString()
|
||||
return `/videoproxy${shortcode}?${params.toString()}`
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ async function proxyResource(url, suggestedHeaders = {}, refreshCallback = null)
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
route: "/imageproxy", methods: ["GET"], code: async (input) => {
|
||||
route: "/imageproxy(/.*)?", methods: ["GET"], code: async (input) => {
|
||||
const verifyResult = verifyURL(input.url)
|
||||
if (verifyResult.status !== "ok") return verifyResult.value
|
||||
if (!["png", "jpg", "webp"].some(ext => verifyResult.url.pathname.endsWith(ext))) return [400, "URL extension is not allowed"]
|
||||
@ -119,7 +119,7 @@ module.exports = [
|
||||
}
|
||||
},
|
||||
{
|
||||
route: "/videoproxy", methods: ["GET"], code: async (input) => {
|
||||
route: "/videoproxy(/.*)?", methods: ["GET"], code: async (input) => {
|
||||
const verifyResult = verifyURL(input.url)
|
||||
if (verifyResult.status !== "ok") return verifyResult.value
|
||||
const url = verifyResult.url
|
||||
|
Loading…
Reference in New Issue
Block a user