This commit is contained in:
2023-10-02 23:10:49 +03:00
commit c6cb488379
255 changed files with 18731 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
<script>
import Icon from "../common/Icon.svelte";
import { imgurl } from "../files/imageserver";
import { getContext } from "svelte";
export let record;
const channel = getContext("channel");
export let size = "small";
export let showFilename = false;
let imageSide;
let fileSide;
let fontSize;
if (size == "large") {
imageSide = 256;
fileSide = 32;
fontSize = "20";
} else if (size == "medium") {
imageSide = 128;
fileSide = 12;
fontSize = "17";
} else if (size == "small") {
imageSide = 64;
fileSide = 12;
fontSize = "15";
} else if (size == "tiny") {
imageSide = 42;
fileSide = 12;
fontSize = "13";
}
</script>
{#if record}
{#if record._file.mime.startsWith("image")}
<!-- href={imgurl(record)} -->
<a
href="{channel.lucentUrl}/records/{record.id}"
title={record._file.path}
class="d-flex align-items-center justify-content-center "
style="width:{imageSide}px;height:{imageSide}px"
>
<img
class="rounded w-100"
src={imgurl(record, imageSide, imageSide, "crop")}
alt={record._file.path}
/>
</a>
{:else}
<!-- href="{channelurl}/files/download?schema={record._sys.schema}&path={record._file.path}" -->
<a
href="{channel.lucentUrl}/records/{record.id}"
title={record._file.path}
class="btn btn-outline-primary btn-sm d-flex align-items-center justify-content-center"
style="width:{imageSide}px;height:{imageSide}px"
>
<Icon icon="file" width={fileSide} height={fileSide} />
<span class="ms-2" style="font-size:{fontSize}px"
>.{record._file.path.split(".").pop()}</span
>
</a>
{/if}
{/if}
{#if showFilename}
<a
href="{channel.lucentUrl}/records/{record.id}"
title={record._file.path}
class="preview-file-filename lx-small-text text-decoration-none"
>{record._file.path}</a
>
{/if}
+67
View File
@@ -0,0 +1,67 @@
<script>
import {createEventDispatcher, getContext} from "svelte";
const dispatch = createEventDispatcher();
const channel = getContext("channel");
export let schema;
let mimeTypes = "";
let files = [];
let isLoading = false;
// export function onUploadComplete(files){
// console.log(files)
// }
function upload(e) {
isLoading = true;
files = e.target.files ? [...e.target.files] : [];
let formData = new FormData();
formData.append("schema", schema.name);
Array.from(files).forEach(function (file) {
formData.append("files[]", file);
});
dispatch("beforeUpload", files);
axios
.post(channel.lucentUrl + "/files/upload", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
.then((response) => {
if (response.data.error) {
dispatch("uploadError", response.data.error);
} else {
dispatch("uploadComplete", response.data);
}
isLoading = false;
})
.catch((error) => {
isLoading = false;
console.log(error.response.data);
});
}
</script>
<fieldset disabled={isLoading}>
<label class="btn btn-primary btn-sm btn-spinner ">
Upload file
<span
class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"
>
<span class="visually-hidden">Loading...</span>
</span>
<input
on:input={upload}
class="form-control"
type="file"
id="formFile"
multiple
accept={mimeTypes}
disabled={isLoading}
hidden
/>
</label>
</fieldset>
+31
View File
@@ -0,0 +1,31 @@
import {getContext} from "svelte";
export function imgurl(record, width = "", height = "", mode = "") {
// let argumentString = "-o";
// if (mode) {
// argumentString += "-mode_fit";
// }
// if (width) {
// argumentString += "-w_" + width;
// }
// if (height) {
// argumentString += "-h_" + height;
// }
// let pathAr = record._file.path.split(".");
// let ext = pathAr.pop();
// let filename = record._file.path.replace("." + ext, "");
// let cache = "cache/"
// if (!mode && !width && !height) {
// argumentString = "";
// cache = "";
// }
const channel = getContext("channel")
return channel.filesUrl + `/thumbs/${record._file.path}`;
}
export function fileurl(record) {
const channel = getContext("channel")
return channel.filesUrl + `/${record._file.path}`;
}