update global (texte + logo)
This commit is contained in:
38
Linkwarden/lib/shared/getArchiveValidity.ts
Normal file
38
Linkwarden/lib/shared/getArchiveValidity.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
|
||||
export function screenshotAvailable(
|
||||
link: LinkIncludingShortenedCollectionAndTags
|
||||
) {
|
||||
return (
|
||||
link &&
|
||||
link.image &&
|
||||
link.image !== "pending" &&
|
||||
link.image !== "unavailable"
|
||||
);
|
||||
}
|
||||
|
||||
export function pdfAvailable(link: LinkIncludingShortenedCollectionAndTags) {
|
||||
return (
|
||||
link && link.pdf && link.pdf !== "pending" && link.pdf !== "unavailable"
|
||||
);
|
||||
}
|
||||
|
||||
export function readabilityAvailable(
|
||||
link: LinkIncludingShortenedCollectionAndTags
|
||||
) {
|
||||
return (
|
||||
link &&
|
||||
link.readable &&
|
||||
link.readable !== "pending" &&
|
||||
link.readable !== "unavailable"
|
||||
);
|
||||
}
|
||||
|
||||
export function previewAvailable(link: any) {
|
||||
return (
|
||||
link &&
|
||||
link.preview &&
|
||||
link.preview !== "pending" &&
|
||||
link.preview !== "unavailable"
|
||||
);
|
||||
}
|
41
Linkwarden/lib/shared/getTitle.ts
Normal file
41
Linkwarden/lib/shared/getTitle.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import fetch from "node-fetch";
|
||||
import https from "https";
|
||||
import { SocksProxyAgent } from "socks-proxy-agent";
|
||||
|
||||
export default async function getTitle(url: string) {
|
||||
try {
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized:
|
||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||
});
|
||||
|
||||
// fetchOpts allows a proxy to be defined
|
||||
let fetchOpts = {
|
||||
agent: httpsAgent,
|
||||
};
|
||||
|
||||
if (process.env.PROXY) {
|
||||
// parse proxy url
|
||||
let proxy = new URL(process.env.PROXY);
|
||||
// if authentication set, apply to proxy URL
|
||||
if (process.env.PROXY_USERNAME) {
|
||||
proxy.username = process.env.PROXY_USERNAME;
|
||||
proxy.password = process.env.PROXY_PASSWORD || "";
|
||||
}
|
||||
|
||||
// add socks5 proxy to fetchOpts
|
||||
fetchOpts = { agent: new SocksProxyAgent(proxy.toString()) }; //TODO: add support for http/https proxies
|
||||
}
|
||||
|
||||
const response = await fetch(url, fetchOpts);
|
||||
|
||||
const text = await response.text();
|
||||
|
||||
// regular expression to find the <title> tag
|
||||
let match = text.match(/<title.*>([^<]*)<\/title>/);
|
||||
if (match) return match[1];
|
||||
else return "";
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
8
Linkwarden/lib/shared/isValidUrl.ts
Normal file
8
Linkwarden/lib/shared/isValidUrl.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export default function isValidUrl(string: string) {
|
||||
try {
|
||||
new URL(string);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user