Files
lucent-laravel/front/js/svelte/files/imageserver.js
T
2024-10-09 23:36:24 +03:00

33 lines
1.0 KiB
JavaScript

export function imgurl(channel, record) {
if (record._file.mime === "image/svg+xml") {
return fileurl(channel, record);
}
const pathAr = record._file.path.split("/");
return channel.disks[record._file.disk] + `/${pathAr[0]}/thumbs/${pathAr[1]}`;
}
export function fileurl(channel, record) {
return channel.disks[record._file.disk] + `/${record._file.path}`;
}
export function htmlurl(channel, record, preset) {
let html = "";
let url = fileurl(channel, record)
if (record._file.width > 0) {
let presetUrl = url;
if (preset) {
const pathAr = record._file.path.split("/");
presetUrl = channel.disks[record._file.disk] + `/${pathAr[0]}/templates/${preset}/${pathAr[1]}`;
}
html = `<img src="${presetUrl}" alt="${record._file.path}" />`
} else if (record._file.mime === "image/svg+xml") {
html = `<img src="${url}" alt="${record._file.path}"/>`
} else {
html = `<a href="${url}">${record._file.originalName}</a>`
}
return html;
}