added AJAX loading for videos
This commit is contained in:
@@ -15,9 +15,9 @@ const epochs = [
|
||||
["second", 1]
|
||||
];
|
||||
const getDuration = timeAgoInSeconds => {
|
||||
for(let [name, seconds] of epochs) {
|
||||
for (let [name, seconds] of epochs) {
|
||||
const interval = ~~(timeAgoInSeconds / seconds);
|
||||
if(interval >= 1) return {
|
||||
if (interval >= 1) return {
|
||||
interval: interval,
|
||||
epoch: name
|
||||
};
|
||||
@@ -32,7 +32,9 @@ export default new class {
|
||||
return (Math.round((b * 8 / s / 1e6) * 1e4) / 1e4);
|
||||
};
|
||||
timeAgo(date) {
|
||||
const { interval, epoch } = getDuration(~~((new Date() - new Date(date)) / 1e3));
|
||||
const duration = getDuration(~~((new Date() - new Date(date)) / 1e3));
|
||||
if (!duration) return "just now";
|
||||
const { interval, epoch } = duration;
|
||||
return `${interval} ${epoch}${interval === 1 ? "" : "s"} ago`;
|
||||
};
|
||||
md5(str) {
|
||||
@@ -40,19 +42,19 @@ export default new class {
|
||||
};
|
||||
getMode(mode) {
|
||||
let tmp;
|
||||
switch(mode) {
|
||||
switch (mode) {
|
||||
case 1: // nsfw
|
||||
tmp = "items.id in (select item_id from tags_assign where tag_id = 2 group by item_id)";
|
||||
break;
|
||||
break;
|
||||
case 2: // untagged
|
||||
tmp = "items.id not in (select item_id from tags_assign group by item_id)";
|
||||
break;
|
||||
break;
|
||||
case 3: // all
|
||||
tmp = "1 = 1";
|
||||
break;
|
||||
break;
|
||||
default: // sfw
|
||||
tmp = "items.id in (select item_id from tags_assign where tag_id = 1 group by item_id)";
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
@@ -61,14 +63,14 @@ export default new class {
|
||||
};
|
||||
genLink(env) {
|
||||
const link = [];
|
||||
if(env.tag) link.push("tag", env.tag);
|
||||
if(env.user) link.push("user", env.user, env.type ?? 'f0cks');
|
||||
if(env.mime?.length > 2) link.push(env.mime);
|
||||
if (env.tag) link.push("tag", env.tag);
|
||||
if (env.user) link.push("user", env.user, env.type ?? 'f0cks');
|
||||
if (env.mime?.length > 2) link.push(env.mime);
|
||||
|
||||
let tmp = link.length === 0 ? '/' : link.join('/');
|
||||
if(!tmp.endsWith('/'))
|
||||
if (!tmp.endsWith('/'))
|
||||
tmp = tmp + '/';
|
||||
if(!tmp.startsWith('/'))
|
||||
if (!tmp.startsWith('/'))
|
||||
tmp = '/' + tmp;
|
||||
|
||||
return {
|
||||
@@ -77,7 +79,7 @@ export default new class {
|
||||
};
|
||||
};
|
||||
parseTag(tag) {
|
||||
if(!tag)
|
||||
if (!tag)
|
||||
return null;
|
||||
return decodeURI(tag);
|
||||
}
|
||||
@@ -129,7 +131,7 @@ export default new class {
|
||||
return "$f0ck$" + salt + ":" + derivedKey.toString("hex");
|
||||
};
|
||||
async verify(str, hash) {
|
||||
const [ salt, key ] = hash.substring(6).split(":");
|
||||
const [salt, key] = hash.substring(6).split(":");
|
||||
const keyBuffer = Buffer.from(key, "hex");
|
||||
const derivedKey = await scrypt(str, salt, 64);
|
||||
return crypto.timingSafeEqual(keyBuffer, derivedKey);
|
||||
@@ -143,20 +145,20 @@ export default new class {
|
||||
where "tags_assign".item_id = ${+itemid}
|
||||
order by "tags".id asc
|
||||
`;
|
||||
for(let t = 0; t < tags.length; t++) {
|
||||
if(tags[t].tag.startsWith(">"))
|
||||
for (let t = 0; t < tags.length; t++) {
|
||||
if (tags[t].tag.startsWith(">"))
|
||||
tags[t].badge = "badge-greentext badge-light";
|
||||
else if(tags[t].normalized === "ukraine")
|
||||
else if (tags[t].normalized === "ukraine")
|
||||
tags[t].badge = "badge-ukraine badge-light";
|
||||
else if(/[а-яё]/.test(tags[t].normalized) || tags[t].normalized === "russia")
|
||||
else if (/[а-яё]/.test(tags[t].normalized) || tags[t].normalized === "russia")
|
||||
tags[t].badge = "badge-russia badge-light";
|
||||
else if(tags[t].normalized === "german")
|
||||
else if (tags[t].normalized === "german")
|
||||
tags[t].badge = "badge-german badge-light";
|
||||
else if(tags[t].normalized === "dutch")
|
||||
else if (tags[t].normalized === "dutch")
|
||||
tags[t].badge = "badge-dutch badge-light";
|
||||
else if(tags[t].normalized === "sfw")
|
||||
else if (tags[t].normalized === "sfw")
|
||||
tags[t].badge = "badge-success";
|
||||
else if(tags[t].normalized === "nsfw")
|
||||
else if (tags[t].normalized === "nsfw")
|
||||
tags[t].badge = "badge-danger";
|
||||
else
|
||||
tags[t].badge = "badge-light";
|
||||
@@ -183,11 +185,11 @@ export default new class {
|
||||
const tmp = Object.values(res)[0];
|
||||
|
||||
let nsfw = false;
|
||||
if(tmp.neutral >= .7)
|
||||
if (tmp.neutral >= .7)
|
||||
nsfw = false;
|
||||
else if((tmp.sexy + tmp.porn + tmp.hentai) >= .7)
|
||||
else if ((tmp.sexy + tmp.porn + tmp.hentai) >= .7)
|
||||
nsfw = true;
|
||||
else if(tmp.drawings >= .4)
|
||||
else if (tmp.drawings >= .4)
|
||||
nsfw = false;
|
||||
else
|
||||
nsfw = false;
|
||||
@@ -197,7 +199,7 @@ export default new class {
|
||||
score: tmp.sexy + tmp.porn + tmp.hentai,
|
||||
scores: tmp
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
async getDefaultAvatar() {
|
||||
return (await db`
|
||||
@@ -212,7 +214,7 @@ export default new class {
|
||||
|
||||
// meddlware admin
|
||||
async auth(req, res, next) {
|
||||
if(!req.session || !req.session.admin) {
|
||||
if (!req.session || !req.session.admin) {
|
||||
return res.reply({
|
||||
code: 401,
|
||||
body: "401 - Unauthorized"
|
||||
@@ -223,7 +225,7 @@ export default new class {
|
||||
|
||||
// meddlware user
|
||||
async userauth(req, res, next) {
|
||||
if(!req.session) {
|
||||
if (!req.session) {
|
||||
return res.reply({
|
||||
code: 401,
|
||||
body: "401 - Unauthorized"
|
||||
@@ -232,14 +234,14 @@ export default new class {
|
||||
return next();
|
||||
};
|
||||
|
||||
async loggedin(req, res, next) {
|
||||
if(!req.session) {
|
||||
return res.reply({
|
||||
code: 401,
|
||||
body: "401 - Unauthorized"
|
||||
});
|
||||
}
|
||||
return next();
|
||||
async loggedin(req, res, next) {
|
||||
if (!req.session) {
|
||||
return res.reply({
|
||||
code: 401,
|
||||
body: "401 - Unauthorized"
|
||||
});
|
||||
}
|
||||
return next();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user