new setting postgrest_subdomain to more easily support onion
This commit is contained in:
parent
7be80cb408
commit
358b63564a
43
script.js
43
script.js
|
@ -296,6 +296,43 @@ function parseRangeHeader(rangeHeader) {
|
|||
* Functions
|
||||
*/
|
||||
|
||||
function replaceSubdomain(newSubdomain) {
|
||||
// Get the current origin
|
||||
const currentOrigin = window.location.origin;
|
||||
|
||||
// Split the current origin into parts
|
||||
const parts = currentOrigin.split('://');
|
||||
|
||||
// Check if there is a subdomain
|
||||
if (parts.length === 2) {
|
||||
const [protocol, domain] = parts;
|
||||
|
||||
// Split the domain into subdomain and top-level domain
|
||||
const domainParts = domain.split('.');
|
||||
|
||||
if (domainParts.length >= 2) {
|
||||
// Replace the subdomain with the new subdomain
|
||||
domainParts[0] = newSubdomain;
|
||||
|
||||
// Join the parts back together to form the new origin
|
||||
const newOrigin = protocol + '://' + domainParts.join('.');
|
||||
|
||||
return newOrigin;
|
||||
}
|
||||
}
|
||||
|
||||
// If there was no subdomain, return the current origin as is
|
||||
return currentOrigin;
|
||||
}
|
||||
|
||||
function getPostgrestRootUrl() {
|
||||
if (GlobalVars.settings.postgrest_url != null) {
|
||||
return GlobalVars.settings.postgrest_url;
|
||||
} else {
|
||||
return replaceSubdomain(GlobalVars.settings.postgrest_subdomain);
|
||||
}
|
||||
}
|
||||
|
||||
function resolveResponse(resolve, reject) {
|
||||
return function(e) {
|
||||
const status = e.target.getResponseHeader("Status");
|
||||
|
@ -829,7 +866,7 @@ function loadKnownSpamPosts(params) {
|
|||
|
||||
console.log("HELLO WORLD 1");
|
||||
|
||||
var url = GlobalVars.settings.postgrest_url + '/known_spam_post?select=*,known_spam_post_attachment(*,phash::text)&order=time_stamp.desc'
|
||||
var url = getPostgrestRootUrl() + '/known_spam_post?select=*,known_spam_post_attachment(*,phash::text)&order=time_stamp.desc'
|
||||
|
||||
const pageNum = Number(params.get(replaceAll(pageName, ' ', '_')) || 0);
|
||||
|
||||
|
@ -891,7 +928,7 @@ function showSpamPost(path_data, _) {
|
|||
pageInfoText.innerText = 'Loading known spam post ' + post_id;
|
||||
|
||||
var url =
|
||||
GlobalVars.settings.postgrest_url
|
||||
getPostgrestRootUrl()
|
||||
+ '/known_spam_post?text_post_id=eq.' + post_id
|
||||
+ '&select=*,known_spam_post_attachment(*,phash::text)'; // Have to load the phash as text here because javascripts json parser won't use BigInt when appropriate because javascript Numbers are based on floats and we're dealing with a 64bit signed int.
|
||||
var headers = {
|
||||
|
@ -934,7 +971,7 @@ function showSpamPost(path_data, _) {
|
|||
.catch(caught.bind(this, "Failed to load known spam post. Reason:"));
|
||||
|
||||
url =
|
||||
GlobalVars.settings.postgrest_url
|
||||
getPostgrestRootUrl()
|
||||
+ '/known_spam_attachments?post_id=eq.' + post_id;
|
||||
|
||||
get(url, cancel, headers)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{
|
||||
"postgrest_subdomain": "pgrest-spam",
|
||||
"postgrest_url": "http://192.168.4.6:3000",
|
||||
"postgrest_url": "http://10.4.0.96:3000",
|
||||
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic3BhbV9ub3RpY2VyIn0.j6-6HSBh-Wf5eQovT9cF1ZCNuxkQOqzBFtE3C8aTG3A",
|
||||
"website_urls": {
|
||||
"leftychan.net": "https://leftychan.net",
|
||||
"leftychan_dev": "http://localhost:8080"
|
||||
"leftychan_dev": "http://10.4.0.96:8080"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue