Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/LanguageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ import {
ListboxOptions,
} from "@headlessui/vue";
import { ChevronUpDownIcon } from "@heroicons/vue/16/solid";
import { ArrowTopRightOnSquareIcon } from "@heroicons/vue/24/outline";
import {
ArrowTopRightOnSquareIcon,
CheckIcon,
} from "@heroicons/vue/24/outline";
import type { Locale } from "vue-i18n";

const { locales, locale: currLocale, setLocale } = useI18n();
Expand Down
8 changes: 8 additions & 0 deletions components/NewsArticleCreateButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<LoadingButton
:loading="loading"
class="bg-blue-600 text-white hover:bg-blue-500"
:disabled="!isValidArticle"
@click="() => createArticle()"
>
{{ $t("news.article.submit") }}
Expand Down Expand Up @@ -235,6 +236,13 @@ const newArticle = ref({
tags: [] as string[],
});

const isValidArticle = computed(
() =>
newArticle.value.title &&
newArticle.value.description &&
newArticle.value.content,
);

const markdownPreview = computed(() => {
// TODO: maybe?? add https://github.com/cure53/DOMPurify
// micromark says its safe, but this is straight html we are injecting
Expand Down
7 changes: 6 additions & 1 deletion error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ async function signIn() {
redirect: `/auth/signin?redirect=${encodeURIComponent(route.fullPath)}`,
});
}
switch (statusCode) {
case 401:
case 403:
await signIn();
}

useHead({
title: t("errors.pageTitle", [statusCode ?? message]),
});

if (import.meta.client) {
console.log(props.error);
console.warn(props.error);
}
</script>

Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,6 @@ export default defineNuxtConfig({
},
rateLimiter: false,
xssValidator: false,
requestSizeLimiter: false,
},
});
2 changes: 1 addition & 1 deletion pages/account/notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</h2>
<button
:disabled="notifications.length === 0"
class="inline-flex items-center justify-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm transition-all duration-200 hover:bg-zinc-700 hover:scale-[1.02] hover:shadow-lg active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-zinc-800 disabled:hover:scale-100 disabled:hover:shadow-none"
class="inline-flex items-center justify-center gap-x-2 rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm transition-all duration-200 hover:bg-zinc-700 hover:scale-[1.02] hover:shadow-lg active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-zinc-800 disabled:hover:scale-100 disabled:hover:shadow-none"
@click="markAllAsRead"
>
<CheckIcon class="size-4" />
Expand Down
4 changes: 2 additions & 2 deletions plugins/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.config.errorHandler = (error, instance, info) => {
nuxtApp.hook("vue:error", (error, instance, info) => {
console.error(error, instance, info);
};
});
});
31 changes: 20 additions & 11 deletions server/api/v1/admin/news/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { ArkErrors, type } from "arktype";
import { defineEventHandler, createError } from "h3";
import aclManager from "~/server/internal/acls";
import newsManager from "~/server/internal/news";
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";

const CreateNews = type({
title: "string",
description: "string",
content: "string",
tags: "string = '[]'",
});

export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["news:create"]);
if (!allowed) throw createError({ statusCode: 403 });
Expand All @@ -23,24 +31,25 @@ export default defineEventHandler(async (h3) => {

const [imageIds, options, pull, _dump] = uploadResult;

const title = options.title;
const description = options.description;
const content = options.content;
const tags = options.tags ? (JSON.parse(options.tags) as string[]) : [];
const imageId = imageIds.at(0);
const body = await CreateNews(options);
if (body instanceof ArkErrors)
throw createError({ statusCode: 400, statusMessage: body.summary });

if (!title || !description || !content)
const parsedTags = JSON.parse(body.tags);
if (typeof parsedTags !== "object" || !Array.isArray(parsedTags))
throw createError({
statusCode: 400,
statusMessage: "Missing or invalid title, description or content.",
statusMessage: "Tags must be an array",
});

const imageId = imageIds.at(0);

const article = await newsManager.create({
title: title,
description: description,
content: content,
title: body.title,
description: body.description,
content: body.content,

tags: tags,
tags: parsedTags,

...(imageId && { image: imageId }),
authorId: "system",
Expand Down
2 changes: 1 addition & 1 deletion server/internal/objects/transactional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ObjectTransactionalHandler {
if (!transaction) return;

let progress = 0;
const increment = (1 / transaction.size) * 100;
const increment = 100 / transaction.size;

for (const [id, data] of transaction) {
if (typeof data === "string") {
Expand Down
11 changes: 9 additions & 2 deletions server/internal/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,15 @@ export function wrapTaskContext(
): TaskRunContext {
return {
progress(progress) {
const scalar = 100 / (options.max - options.min);
const adjustedProgress = progress * scalar + options.min;
if (progress > 100 || progress < 0) {
console.warn("[wrapTaskContext] progress must be between 0 and 100");
}

// I was too tired to figure this out
// https://stackoverflow.com/a/929107
const oldRange = 100;
const newRange = options.max - options.min;
const adjustedProgress = (progress * newRange) / oldRange + options.min;
return context.progress(adjustedProgress);
},
log(message) {
Expand Down
27 changes: 0 additions & 27 deletions server/plugins/redirect.ts

This file was deleted.