support Nextcloud OAuth 2.0 authentication

This commit is contained in:
MaysWind
2025-10-21 01:52:28 +08:00
parent 600ae2bd58
commit 53a8ad71c6
74 changed files with 2046 additions and 241 deletions
+50 -6
View File
@@ -160,6 +160,7 @@ import { UTC_TIMEZONE, ALL_TIMEZONES } from '@/consts/timezone.ts';
import { ALL_CURRENCIES } from '@/consts/currency.ts';
import { DEFAULT_EXPENSE_CATEGORIES, DEFAULT_INCOME_CATEGORIES, DEFAULT_TRANSFER_CATEGORIES } from '@/consts/category.ts';
import { KnownErrorCode, SPECIFIED_API_NOT_FOUND_ERRORS, PARAMETERIZED_ERRORS } from '@/consts/api.ts';
import { OAUTH2_PROVIDER_DISPLAY_NAME } from '@/consts/oauth2.ts';
import { DEFAULT_DOCUMENT_LANGUAGE_FOR_IMPORT_FILE, SUPPORTED_DOCUMENT_LANGUAGES_FOR_IMPORT_FILE, SUPPORTED_IMPORT_FILE_CATEGORY_AND_TYPES } from '@/consts/file.ts';
import {
@@ -870,18 +871,18 @@ export function useI18n() {
return textArray.join(separator);
}
function getServerTipContent(tipConfig: Record<string, string>): string {
if (!tipConfig) {
function getServerMultiLanguageConfigContent(multiLanguageConfig: Record<string, string>): string {
if (!multiLanguageConfig) {
return '';
}
const currentLanguage = getCurrentLanguageTag();
if (isString(tipConfig[currentLanguage])) {
return tipConfig[currentLanguage];
if (isString(multiLanguageConfig[currentLanguage])) {
return multiLanguageConfig[currentLanguage];
}
return tipConfig['default'] || '';
return multiLanguageConfig['default'] || '';
}
function getCurrentLanguageTag(): string {
@@ -2139,6 +2140,46 @@ export function useI18n() {
return ret;
}
function getLocalizedOAuth2ProviderName(oauth2Provider: string, oidcDisplayNames: Record<string, string>): string {
if (oauth2Provider === 'oidc') {
const providerDisplayName = getServerMultiLanguageConfigContent(oidcDisplayNames);
if (providerDisplayName) {
return providerDisplayName;
} else {
return 'Connect ID';
}
} else {
const providerDisplayName = OAUTH2_PROVIDER_DISPLAY_NAME[oauth2Provider];
if (providerDisplayName) {
return providerDisplayName;
} else {
return 'OAuth 2.0';
}
}
}
function getLocalizedOAuth2LoginText(oauth2Provider: string, oidcDisplayNames: Record<string, string>): string {
if (oauth2Provider === 'oidc') {
const providerDisplayName = getServerMultiLanguageConfigContent(oidcDisplayNames);
if (providerDisplayName) {
return t('format.misc.loginWithCustomProvider', { name: providerDisplayName });
} else {
return t('Log in with Connect ID');
}
} else {
const providerDisplayName = OAUTH2_PROVIDER_DISPLAY_NAME[oauth2Provider];
if (providerDisplayName) {
return t('format.misc.loginWithCustomProvider', { name: providerDisplayName });
} else {
return t('Log in with OAuth 2.0');
}
}
}
function setLanguage(languageKey: string | null, force?: boolean): LocaleDefaultSettings | null {
if (!languageKey) {
languageKey = getDefaultLanguage();
@@ -2266,7 +2307,7 @@ export function useI18n() {
ti: translateIf,
te: translateError,
joinMultiText,
getServerTipContent,
getServerMultiLanguageConfigContent,
// get current language info
getCurrentLanguageTag,
getCurrentLanguageInfo,
@@ -2411,6 +2452,9 @@ export function useI18n() {
getAdaptiveAmountRate,
getAmountPrependAndAppendText,
getCategorizedAccountsWithDisplayBalance,
// other format functions
getLocalizedOAuth2ProviderName,
getLocalizedOAuth2LoginText,
// localization setting functions
setLanguage,
setTimeZone,