all developments of milestone 1
This commit is contained in:
@@ -69,10 +69,15 @@ function formatDateTimeForEvent(dateTime: Date, locale: Locale): string {
|
||||
return format(dateTime, "PPp", { locale });
|
||||
}
|
||||
|
||||
function formatDateForEvent(dateTime: Date, locale: Locale): string {
|
||||
return format(dateTime, "PP", { locale });
|
||||
}
|
||||
|
||||
export {
|
||||
localeMonthNames,
|
||||
localeShortWeekDayNames,
|
||||
formatBytes,
|
||||
roundToNearestMinute,
|
||||
formatDateTimeForEvent,
|
||||
formatDateForEvent,
|
||||
};
|
||||
|
||||
22
src/utils/head.ts
Normal file
22
src/utils/head.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { computed } from "vue";
|
||||
import { provideApolloClient, useQuery } from "@vue/apollo-composable";
|
||||
import { useHead as unHead } from "@unhead/vue";
|
||||
import { apolloClient } from "@/vue-apollo";
|
||||
import { IConfig } from "@/types/config.model";
|
||||
import { ABOUT } from "@/graphql/config";
|
||||
|
||||
const { result } = provideApolloClient(apolloClient)(() =>
|
||||
useQuery<{ config: Pick<IConfig, "name"> }>(ABOUT)
|
||||
);
|
||||
const instanceName = computed(() => result.value?.config?.name);
|
||||
|
||||
export function useHead(args: any) {
|
||||
return unHead({
|
||||
...args,
|
||||
title: computed(() =>
|
||||
args?.title?.value
|
||||
? `${args.title.value} - ${instanceName.value}`
|
||||
: instanceName.value
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IMedia } from "@/types/media.model";
|
||||
import { IMedia, IModifiableMedia } from "@/types/media.model";
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
export async function buildFileFromIMedia(
|
||||
obj: IMedia | null | undefined
|
||||
@@ -29,18 +30,83 @@ export function buildFileVariable(
|
||||
};
|
||||
}
|
||||
|
||||
export function readFileAsync(
|
||||
file: File
|
||||
): Promise<string | ArrayBuffer | null> {
|
||||
export function readFileAsync(file: File): Promise<ArrayBuffer | null> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
resolve(reader.result);
|
||||
resolve(reader.result as ArrayBuffer);
|
||||
};
|
||||
|
||||
reader.onerror = reject;
|
||||
|
||||
reader.readAsBinaryString(file);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
export async function fileHash(file: File): Promise<string | null> {
|
||||
const data = await readFileAsync(file);
|
||||
if (data === null) return null;
|
||||
const hash = await crypto.subtle.digest("SHA-1", data);
|
||||
const b64Hash = btoa(
|
||||
Array.from(new Uint8Array(hash))
|
||||
.map((b) => String.fromCharCode(b))
|
||||
.join("")
|
||||
);
|
||||
return b64Hash;
|
||||
}
|
||||
|
||||
export function initWrappedMedia(): IModifiableMedia {
|
||||
return {
|
||||
file: ref<File | null>(null),
|
||||
firstHash: null,
|
||||
hash: null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadWrappedMedia(
|
||||
modifiableMedia: IModifiableMedia,
|
||||
media: IMedia | null
|
||||
) {
|
||||
watch(modifiableMedia.file, async () => {
|
||||
if (modifiableMedia.file.value) {
|
||||
modifiableMedia.hash = await fileHash(modifiableMedia.file.value);
|
||||
} else {
|
||||
modifiableMedia.hash = null;
|
||||
}
|
||||
});
|
||||
try {
|
||||
modifiableMedia.file.value = await buildFileFromIMedia(media);
|
||||
} catch (e) {
|
||||
console.error("catched error while building media", e);
|
||||
}
|
||||
if (modifiableMedia.file.value) {
|
||||
modifiableMedia.firstHash = await fileHash(modifiableMedia.file.value);
|
||||
}
|
||||
}
|
||||
|
||||
export function asMediaInput(
|
||||
mmedia: IModifiableMedia,
|
||||
name: string,
|
||||
fallbackId: number
|
||||
): any {
|
||||
const ret = {
|
||||
[name]: {},
|
||||
};
|
||||
if (mmedia.file.value) {
|
||||
if (mmedia.firstHash != mmedia.hash) {
|
||||
ret[name] = {
|
||||
media: {
|
||||
name: mmedia.file.value?.name,
|
||||
alt: "",
|
||||
file: mmedia.file.value,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
ret[name] = {
|
||||
mediaId: fallbackId,
|
||||
};
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user