40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
export function imgurl(channel, file) {
|
|
if (file.mime === "image/svg+xml") {
|
|
return fileurl(channel, file);
|
|
}
|
|
const webpPath = file.path.slice(0, file.path.lastIndexOf(".")) + ".webp";
|
|
return channel.filesUrl + `/thumbs/${webpPath}`;
|
|
}
|
|
|
|
export function presetUrl(channel, file, preset) {
|
|
if (file.mime === "image/svg+xml") {
|
|
return fileurl(channel, file);
|
|
}
|
|
const webpPath = file.path.slice(0, file.path.lastIndexOf(".")) + ".webp";
|
|
return channel.filesUrl + `/templates/${preset}/${webpPath}`;
|
|
}
|
|
|
|
export function fileurl(channel, file) {
|
|
return channel.filesUrl + `/${file.path}`;
|
|
}
|
|
|
|
export function htmlurl(channel, file, preset) {
|
|
let html = "";
|
|
let url = fileurl(channel, file);
|
|
|
|
if (file.width > 0) {
|
|
let presetUrl = url;
|
|
if (preset) {
|
|
const webpPath = file.path.slice(0, file.path.lastIndexOf(".")) + ".webp";
|
|
presetUrl = channel.filesUrl + `/templates/${preset}/${webpPath}`;
|
|
}
|
|
html = `<img src="${presetUrl}" alt="${file.path}" />`;
|
|
} else if (file.mime === "image/svg+xml") {
|
|
html = `<img src="${url}" alt="${file.path}"/>`;
|
|
} else {
|
|
html = `<a href="${url}">${file.filename}</a>`;
|
|
}
|
|
|
|
return html;
|
|
}
|