mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
some typescript typing fixes
This commit is contained in:
parent
a10eda3cf9
commit
866e15a6b5
@ -1,15 +1,17 @@
|
||||
import { AxiosError } from "axios";
|
||||
import { HangarApiException, HangarValidationException, MultiHangarApiException } from "hangar-api";
|
||||
import { Composer, VueMessageType } from "vue-i18n";
|
||||
import { Composer, UseI18nOptions } from "vue-i18n";
|
||||
import { Context } from "vite-ssr/vue";
|
||||
import { useNotificationStore } from "~/lib/store/notification";
|
||||
|
||||
export function handleRequestError(
|
||||
err: AxiosError,
|
||||
{ writeResponse }: Context,
|
||||
i18n: Composer<unknown, unknown, unknown, VueMessageType>,
|
||||
msg: string | undefined = undefined
|
||||
) {
|
||||
type I18nType = Composer<
|
||||
NonNullable<UseI18nOptions["messages"]>,
|
||||
NonNullable<UseI18nOptions["datetimeFormats"]>,
|
||||
NonNullable<UseI18nOptions["numberFormats"]>,
|
||||
NonNullable<UseI18nOptions["locale"]>
|
||||
>;
|
||||
|
||||
export function handleRequestError(err: AxiosError, { writeResponse }: Context, i18n: I18nType, msg: string | undefined = undefined) {
|
||||
if (import.meta.env.SSR) {
|
||||
_handleRequestError(err, writeResponse, i18n);
|
||||
return;
|
||||
@ -40,7 +42,7 @@ export function handleRequestError(
|
||||
}
|
||||
}
|
||||
|
||||
function _handleRequestError(err: AxiosError, writeResponse: Context["writeResponse"], i18n: Composer<unknown, unknown, unknown, VueMessageType>) {
|
||||
function _handleRequestError(err: AxiosError, writeResponse: Context["writeResponse"], i18n: I18nType) {
|
||||
if (!err.isAxiosError) {
|
||||
// everything should be an AxiosError
|
||||
writeResponse({
|
||||
|
@ -1,27 +1,25 @@
|
||||
import { helpers } from "@vuelidate/validators";
|
||||
import { useInternalApi } from "~/composables/useApi";
|
||||
import { ValidationRule } from "@vuelidate/core";
|
||||
import { withOverrideMessage } from "~/lib/composables/useValidationHelpers";
|
||||
|
||||
export const validProjectName = withOverrideMessage(
|
||||
(ownerId: () => string) =>
|
||||
helpers.withParams(
|
||||
{ ownerId, type: "validProjectName" },
|
||||
helpers.withAsync(async (value: string) => {
|
||||
if (!helpers.req(value)) {
|
||||
return { $valid: true };
|
||||
}
|
||||
try {
|
||||
await useInternalApi("projects/validateName", false, "get", {
|
||||
userId: ownerId(),
|
||||
value: value,
|
||||
});
|
||||
return { $valid: true };
|
||||
} catch (e: any) {
|
||||
return !e.response?.data.isHangarApiException ? { $valid: false } : { $valid: false, $message: e.response?.data.message };
|
||||
}
|
||||
})
|
||||
) as ValidationRule<{ ownerId: string }>
|
||||
export const validProjectName = withOverrideMessage((ownerId: () => string) =>
|
||||
helpers.withParams(
|
||||
{ ownerId, type: "validProjectName" },
|
||||
helpers.withAsync(async (value: string) => {
|
||||
if (!helpers.req(value)) {
|
||||
return { $valid: true };
|
||||
}
|
||||
try {
|
||||
await useInternalApi("projects/validateName", false, "get", {
|
||||
userId: ownerId(),
|
||||
value: value,
|
||||
});
|
||||
return { $valid: true };
|
||||
} catch (e: any) {
|
||||
return !e.response?.data.isHangarApiException ? { $valid: false } : { $valid: false, $message: e.response?.data.message };
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export const validOrgName = withOverrideMessage(
|
||||
@ -45,24 +43,23 @@ export const validOrgName = withOverrideMessage(
|
||||
})
|
||||
);
|
||||
|
||||
export const validApiKeyName = withOverrideMessage(
|
||||
(username: string) =>
|
||||
helpers.withParams(
|
||||
{ username, type: "validApiKeyName" },
|
||||
helpers.withAsync(async (value: string) => {
|
||||
if (!helpers.req(value)) {
|
||||
return { $valid: true };
|
||||
}
|
||||
try {
|
||||
await useInternalApi(`api-keys/check-key/${username}`, true, "get", {
|
||||
name: value,
|
||||
});
|
||||
return { $valid: true };
|
||||
} catch (e: any) {
|
||||
return !e.response?.data.isHangarApiException ? { $valid: false } : { $valid: false, $message: e.response?.data.message };
|
||||
}
|
||||
})
|
||||
) as ValidationRule<{ ownerId: string }>
|
||||
export const validApiKeyName = withOverrideMessage((username: string) =>
|
||||
helpers.withParams(
|
||||
{ username, type: "validApiKeyName" },
|
||||
helpers.withAsync(async (value: string) => {
|
||||
if (!helpers.req(value)) {
|
||||
return { $valid: true };
|
||||
}
|
||||
try {
|
||||
await useInternalApi(`api-keys/check-key/${username}`, true, "get", {
|
||||
name: value,
|
||||
});
|
||||
return { $valid: true };
|
||||
} catch (e: any) {
|
||||
return !e.response?.data.isHangarApiException ? { $valid: false } : { $valid: false, $message: e.response?.data.message };
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export const validChannelName = withOverrideMessage((projectId: string, existingName: string) =>
|
||||
|
@ -136,7 +136,7 @@ async function save() {
|
||||
...form,
|
||||
});
|
||||
await router.go(0);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
loading.save = false;
|
||||
@ -149,7 +149,7 @@ async function transfer() {
|
||||
content: search.value,
|
||||
});
|
||||
notificationStore.success(i18n.t("project.settings.success.transferRequest", [search.value]));
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
loading.transfer = false;
|
||||
@ -163,7 +163,7 @@ async function rename() {
|
||||
});
|
||||
notificationStore.success(i18n.t("project.settings.success.rename", [newName.value]));
|
||||
await router.push("/" + route.params.user + "/" + newSlug);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
loading.rename = false;
|
||||
@ -180,7 +180,7 @@ async function softDelete(comment: string) {
|
||||
} else {
|
||||
await router.push("/");
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
}
|
||||
@ -192,7 +192,7 @@ async function hardDelete(comment: string) {
|
||||
});
|
||||
notificationStore.success(i18n.t("project.settings.success.hardDelete"));
|
||||
await router.push("/");
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ async function uploadIcon() {
|
||||
cropperResult.value = null;
|
||||
await loadIconIntoCropper();
|
||||
notificationStore.success(i18n.t("project.settings.success.changedIcon"));
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
loading.uploadIcon = false;
|
||||
@ -223,7 +223,7 @@ async function resetIcon() {
|
||||
useNotificationStore().success(i18n.t("project.settings.success.resetIcon"));
|
||||
projectIcon.value = null;
|
||||
await loadIconIntoCropper();
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
handleRequestError(e, ctx, i18n);
|
||||
}
|
||||
loading.resetIcon = false;
|
||||
|
@ -21,6 +21,7 @@ import { maxLength, minLength, required } from "~/lib/composables/useValidationH
|
||||
import { validApiKeyName } from "~/composables/useHangarValidations";
|
||||
import { useVuelidate } from "@vuelidate/core";
|
||||
import InputGroup from "~/lib/components/ui/InputGroup.vue";
|
||||
import { NamedPermission } from "~/types/enums";
|
||||
|
||||
const ctx = useContext();
|
||||
const i18n = useI18n();
|
||||
@ -33,7 +34,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const apiKeys = ref(await useInternalApi<ApiKey[]>("api-keys/existing-keys/" + route.params.user));
|
||||
const possiblePerms = await useInternalApi<IPermission[]>("api-keys/possible-perms/" + route.params.user);
|
||||
const possiblePerms = await useInternalApi<NamedPermission[]>("api-keys/possible-perms/" + route.params.user);
|
||||
|
||||
const name = ref("");
|
||||
const loadingCreate = ref(false);
|
||||
|
@ -95,13 +95,13 @@ export const useBackendDataStore = defineStore("backendData", () => {
|
||||
fetchIfNeeded(async () => useInternalApi<string[]>("data/licenses", false), licenses),
|
||||
fetchIfNeeded(async () => useInternalApi<AnnouncementObject[]>("data/announcements", false), announcements),
|
||||
fetchIfNeeded(async () => useInternalApi<IVisibility[]>("data/visibilities", false), visibilities),
|
||||
fetchIfNeeded(async () => useInternalApi("data/validations", false), validations),
|
||||
fetchIfNeeded(async () => useInternalApi("data/orgRoles", false), orgRoles),
|
||||
fetchIfNeeded(async () => useInternalApi("data/channelColors", false), channelColors),
|
||||
fetchIfNeeded(async () => useInternalApi("data/projectRoles", false), projectRoles),
|
||||
fetchIfNeeded(async () => useInternalApi("data/globalRoles", false), globalRoles),
|
||||
fetchIfNeeded(async () => useInternalApi("data/flagReasons", false), flagReasons),
|
||||
fetchIfNeeded(async () => useInternalApi("data/version-info", false), versionInfo),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof validations.value>>("data/validations", false), validations),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof orgRoles.value>>("data/orgRoles", false), orgRoles),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof channelColors.value>>("data/channelColors", false), channelColors),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof projectRoles.value>>("data/projectRoles", false), projectRoles),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof globalRoles.value>>("data/globalRoles", false), globalRoles),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof flagReasons.value>>("data/flagReasons", false), flagReasons),
|
||||
fetchIfNeeded(async () => useInternalApi<NonNullable<typeof versionInfo.value>>("data/version-info", false), versionInfo),
|
||||
]);
|
||||
} catch (e) {
|
||||
console.error("ERROR FETCHING BACKEND DATA");
|
||||
|
Loading…
Reference in New Issue
Block a user