Skip to content

Commit

Permalink
feat!: nexcloud uri parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Jun 10, 2024
1 parent d40aa5c commit 545a87d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 13 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
VITE_BASE_URI="/"
VITE_API_URI="/"
VITE_NEXTCLOUD_URI="/nextcloud"
VITE_AXIOS_TIMEOUT=10000

VITE_PROXY_API_URL="http://localhost:8090"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class FrontProperties {

private String userInfoApiUrl;
private String nextcloudUri;
private CollaborationProperties collaboration = new CollaborationProperties();
private ExtendedUportalHeaderProperties extendedUportalHeader = new ExtendedUportalHeaderProperties();
private ExtendedUportalFooterProperties extendedUportalFooter = new ExtendedUportalFooterProperties();
Expand Down Expand Up @@ -115,6 +116,7 @@ public String toString() {
public String toString() {
return "\"FrontProperties\": {" +
"\n\t\"userInfoApiUrl\": \"" + userInfoApiUrl + "\"," +
"\n\t\"nextcloudUri\": \"" + nextcloudUri + "\"," +
"\n\t\"collaboration\": \"" + collaboration + "\"," +
"\n\t\"extendedUportalHeader\": \"" + extendedUportalHeader + "\"," +
"\n\t\"extendedUportalFooter\": \"" + extendedUportalFooter + "\"" +
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application-dev.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ app:
front:
user-info-api-url: ''

nextcloud-uri: '' # You can use domain variable in case of subdomain hosting (ex: 'https://nc.${domain}')

collaboration:
websocket-api-url: ''

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config/application-prod.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ app:
cors:
enable: true
allowed-origins:
- https://*.giprecia.net
-

soffit:
jwt-signature-key: ''
Expand All @@ -33,6 +33,8 @@ app:
front:
user-info-api-url: ''

nextcloud-uri: ''

collaboration:
websocket-api-url: ''

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ app:
front:
user-info-api-url: ''

nextcloud-uri: ''

collaboration:
websocket-api-url: ''

Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/src/components/FileMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const appStore = useAppStore();
const { isApp } = storeToRefs(appStore);
const configurationStore = useConfigurationStore();
const { isSettings } = storeToRefs(configurationStore);
const { isNextcloudAvailable, isSettings } = storeToRefs(configurationStore);
const fileStore = useFileStore();
const { loadFile } = fileStore;
Expand Down Expand Up @@ -63,7 +63,7 @@ const onHistories = async (): Promise<void> => {
const onExport = async (): Promise<void> => {
await getFile();
if (!file.value) return;
if (!file.value || !isNextcloudAvailable.value) return;
await saveOnNextcloud(toFile(file.value), file.value.associatedApp.extension);
};
Expand Down Expand Up @@ -119,6 +119,7 @@ const onDelete = async (): Promise<void> => {
@click="onHistories"
/>
<v-list-item
v-if="isNextcloudAvailable"
prepend-icon="fas fa-cloud"
:title="t('menu.item.exportOnNextcloud')"
rounded="xl"
Expand Down
14 changes: 11 additions & 3 deletions src/main/webapp/src/stores/configurationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Configuration } from '@/types/configurationType.ts';
import type { Soffit } from '@/types/soffitType.ts';
import { errorHandler, initToken } from '@/utils/axiosUtils.ts';
import { useEntTheme } from '@/utils/entUtils.ts';
import { setNextcloudUri } from '@/utils/nextcloudUtils.ts';
import { initAppsRoutes } from '@/utils/routerUtils.ts';
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
Expand All @@ -19,9 +20,11 @@ export const useConfigurationStore = defineStore('configuration', () => {
try {
const response = await getConfiguration();
configuration.value = response.data;
await initToken(configuration.value!.front.userInfoApiUrl);
await useEntTheme(configuration.value!.front.extendedUportalHeader.templateApiPath);
await initAppsRoutes(configuration.value!.front.apps);
if (!configuration.value) return false;
if (isNextcloudAvailable.value) setNextcloudUri(configuration.value.front.nextcloudUri);
await initToken(configuration.value.front.userInfoApiUrl);
await useEntTheme(configuration.value.front.extendedUportalHeader.templateApiPath);
await initAppsRoutes(configuration.value.front.apps);

return true;
} catch (e) {
Expand All @@ -35,6 +38,10 @@ export const useConfigurationStore = defineStore('configuration', () => {

const isReady = computed<boolean>(() => isInit.value && isSoffitOk.value);

/* -- Gestion de nextcloud -- */

const isNextcloudAvailable = computed<boolean>(() => (configuration.value?.front.nextcloudUri ?? '').length > 0);

/* -- Gestion de l'utilisateur -- */

const user = ref<Soffit>({ sub: 'guest', token: undefined });
Expand All @@ -61,6 +68,7 @@ export const useConfigurationStore = defineStore('configuration', () => {
init,
isInit,
isReady,
isNextcloudAvailable,
user,
isSoffitOk,
lastNavigation,
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/src/types/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AssociatedApp } from '@/types/associatedAppType.ts';
export type Configuration = {
front: {
userInfoApiUrl: string;
nextcloudUri: string;
collaboration: {
websocketApiUrl: string;
};
Expand Down
18 changes: 13 additions & 5 deletions src/main/webapp/src/utils/nextcloudUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ import i18n from '@/plugins/i18n.ts';
import { saveNcFile } from '@/services/api/nextcloudService.ts';
import { useConfigurationStore } from '@/stores/configurationStore.ts';
import { errorHandler } from '@/utils/axiosUtils.ts';
import { interpolate } from '@/utils/stringUtils.ts';
import axios from 'axios';
import { storeToRefs } from 'pinia';
import { toast } from 'vue3-toastify';

const { VITE_NEXTCLOUD_URI, VITE_AXIOS_TIMEOUT } = import.meta.env;
const { VITE_AXIOS_TIMEOUT } = import.meta.env;

const { t } = i18n.global;

let nextcloudBaseUri: string | undefined;

const instance = axios.create({
baseURL: `${VITE_NEXTCLOUD_URI}/remote.php/dav/files/`,
timeout: VITE_AXIOS_TIMEOUT,
headers: {
Authorization: 'Bearer null',
},
});

const setNextcloudUri = (uri: string): void => {
if (uri.length <= 0) return;
nextcloudBaseUri = interpolate(uri, { domain: window.location.hostname });
instance.defaults.baseURL = `${nextcloudBaseUri}/remote.php/dav/files/`;
};

const saveOnNextcloud = async (file: File, type: string): Promise<void> => {
const configurationStore = useConfigurationStore();
const { user } = storeToRefs(configurationStore);
Expand All @@ -32,7 +40,7 @@ const saveOnNextcloud = async (file: File, type: string): Promise<void> => {
}),
{
onClick: () => {
window.open(`${VITE_NEXTCLOUD_URI}/`, '_blank');
window.open(`${nextcloudBaseUri}/`, '_blank');
},
},
);
Expand All @@ -42,11 +50,11 @@ const saveOnNextcloud = async (file: File, type: string): Promise<void> => {
toast.error(t('toast.nextcloud.401'), {
autoClose: false,
onClick: () => {
window.open(`${VITE_NEXTCLOUD_URI}/apps/user_cas/login`, '_blank');
window.open(`${nextcloudBaseUri}/apps/user_cas/login`, '_blank');
},
});
} else errorHandler(error, true);
}
};

export { instance, saveOnNextcloud };
export { instance, setNextcloudUri, saveOnNextcloud };
9 changes: 8 additions & 1 deletion src/main/webapp/src/utils/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ const slugify = (value: string): string => {
.replace(/-+/g, '-'); // remove consecutive hyphens
};

export { capitalize, charOTP, slugify };
const interpolate = (input: string, params: Object): string => {
const names = Object.keys(params);
const vals = Object.values(params);

return new Function(...names, `return \`${input}\`;`)(...vals);
};

export { capitalize, charOTP, slugify, interpolate };

0 comments on commit 545a87d

Please sign in to comment.