Support Global Application (#231)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
4c38327f16
commit
55482163d2
63 files changed
+2697
-2719
No files matched your search
@@ -29,12 +29,12 @@ export const setApplication = async ({ commit, dispatch }: any, payload: IApplic
|
||||
};
|
||||
|
||||
export const setApplications = async ({ commit }: any, payload: IApplication[]): Promise<void> => {
|
||||
console.debug('set applications', payload);
|
||||
console.debug('set applications for chat', payload);
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
console.debug('set service', payload);
|
||||
console.debug('set service for chat', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
@@ -45,12 +45,12 @@ export const setCredential = async ({ commit }: any, payload: ICredential): Prom
|
||||
|
||||
export const createCredential = async ({ commit, state }: any): Promise<ICredential | undefined> => {
|
||||
const application = state.application;
|
||||
console.debug('prepare to create credential for application', application);
|
||||
console.debug('prepare to create credential for application for chat', application);
|
||||
if (!application) {
|
||||
console.error('Application not found');
|
||||
return undefined;
|
||||
}
|
||||
console.debug('creating create credential for application', application);
|
||||
console.debug('creating create credential for application for chat', application);
|
||||
const { data: credential } = await credentialOperator.create({
|
||||
application_id: application?.id,
|
||||
host: window.location.origin
|
||||
@@ -84,29 +84,18 @@ export const getApplications = async ({
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IApplication[] | undefined> => {
|
||||
console.debug('start to get applications for chat');
|
||||
state.status.getApplications = Status.Request;
|
||||
const currentApplication = state.application;
|
||||
console.debug('current application', currentApplication);
|
||||
try {
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: rootState?.user?.id,
|
||||
service_id: CHAT_SERVICE_ID
|
||||
});
|
||||
console.debug('get applications success', applications);
|
||||
console.debug('get applications success for chat', applications);
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
console.debug('set applications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
console.debug('final application', finalApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
commit('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
console.debug('set applications for chat', applications.items);
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
console.error('get applications failed for chat', error);
|
||||
state.status.getApplications = Status.Error;
|
||||
commit('setApplications', undefined);
|
||||
commit('setApplication', undefined);
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState } from './models';
|
||||
import { userOperator, oauthOperator, siteOperator, exchangeOperator } from '@/operators';
|
||||
import { IToken, IUser } from '@/models';
|
||||
import {
|
||||
userOperator,
|
||||
oauthOperator,
|
||||
siteOperator,
|
||||
exchangeOperator,
|
||||
applicationOperator,
|
||||
credentialOperator
|
||||
} from '@/operators';
|
||||
import { IApplication, IApplicationScope, IApplicationType, ICredential, IToken, IUser, Status } from '@/models';
|
||||
import { getSiteOrigin } from '@/utils/site';
|
||||
import { loginRedirect } from '@/utils';
|
||||
import { SURFACE_ANDROID, SURFACE_IOS } from '@/constants';
|
||||
@@ -138,6 +145,56 @@ export const getSite = async ({ state, commit }: ActionContext<IRootState, IRoot
|
||||
}
|
||||
};
|
||||
|
||||
export const setApplications = async ({ commit }: any, payload: IApplication[]): Promise<void> => {
|
||||
console.debug('set applications', payload);
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export const getApplications = async ({
|
||||
commit,
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IRootState, IRootState>): Promise<IApplication[] | undefined> => {
|
||||
console.debug('start to get applications for global');
|
||||
state.status.getApplications = Status.Request;
|
||||
try {
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
user_id: rootState?.user?.id,
|
||||
ordering: '-created_at',
|
||||
type: IApplicationType.USAGE,
|
||||
scope: IApplicationScope.GLOBAL
|
||||
});
|
||||
console.debug('global applications from online', applications);
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed for global', error);
|
||||
state.status.getApplications = Status.Error;
|
||||
commit('setApplications', undefined);
|
||||
}
|
||||
};
|
||||
|
||||
export const createCredential = async ({ commit, state }: any): Promise<ICredential | undefined> => {
|
||||
const application = state.application;
|
||||
console.debug('prepare to create credential for application', application);
|
||||
if (!application) {
|
||||
console.error('Application not found');
|
||||
return undefined;
|
||||
}
|
||||
console.debug('creating create credential for application', application);
|
||||
const { data: credential } = await credentialOperator.create({
|
||||
application_id: application?.id,
|
||||
host: window.location.origin
|
||||
});
|
||||
console.debug('created credential success', credential);
|
||||
commit('setCredential', credential);
|
||||
console.debug('end createCredential');
|
||||
return credential;
|
||||
};
|
||||
|
||||
export const login = async ({ state, commit }: ActionContext<IRootState, IRootState>) => {
|
||||
const site = state?.site?.origin;
|
||||
if (import.meta.env.VITE_SURFACE === SURFACE_IOS || import.meta.env.VITE_SURFACE === SURFACE_ANDROID) {
|
||||
@@ -187,5 +244,8 @@ export default {
|
||||
getUser,
|
||||
initializeSite,
|
||||
getSite,
|
||||
setExchange
|
||||
setExchange,
|
||||
setApplications,
|
||||
getApplications,
|
||||
createCredential
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ISite, IToken, IUser } from '@/models';
|
||||
import { IApplication, ICredential, ISite, IToken, IUser, Status } from '@/models';
|
||||
import { IMidjourneyState } from '../midjourney/models';
|
||||
import { IChatState } from '../chat/models';
|
||||
import { IQrartState } from '../qrart/models';
|
||||
@@ -28,6 +28,12 @@ export interface ICommonState {
|
||||
[key: string]: number;
|
||||
}
|
||||
| undefined;
|
||||
applications: IApplication[] | undefined;
|
||||
status: {
|
||||
getService: Status | undefined;
|
||||
getApplications: Status | undefined;
|
||||
getTasks: Status | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IAppState {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IUser } from '@/models';
|
||||
import { IApplication, IUser } from '@/models';
|
||||
import { IRootState } from './models';
|
||||
|
||||
export const setUser = (state: IRootState, payload: IUser): void => {
|
||||
@@ -56,6 +56,11 @@ export const setCurrency = (state: IRootState, payload: string): void => {
|
||||
state.currency = payload;
|
||||
};
|
||||
|
||||
export const setApplications = (state: IRootState, payload: IApplication[]): void => {
|
||||
console.debug('set applications for global', payload);
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setUser,
|
||||
setSite,
|
||||
@@ -66,5 +71,6 @@ export default {
|
||||
setFingerprint,
|
||||
setToken,
|
||||
resetToken,
|
||||
resetSite
|
||||
resetSite,
|
||||
setApplications
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import headshotsState from '../headshots/state';
|
||||
|
||||
export default (): IRootState => {
|
||||
return {
|
||||
applications: [],
|
||||
fingerprint: undefined,
|
||||
currency: 'usd',
|
||||
exchange: undefined,
|
||||
@@ -25,6 +26,11 @@ export default (): IRootState => {
|
||||
refresh: undefined,
|
||||
expiration: undefined
|
||||
},
|
||||
status: {
|
||||
getService: undefined,
|
||||
getApplications: undefined,
|
||||
getTasks: undefined
|
||||
},
|
||||
setting: {},
|
||||
site: {},
|
||||
chat: chatState(),
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IFluxConfig, IFluxTask, IService } from '@/m
|
||||
import { Status } from '@/models/common';
|
||||
import { FLUX_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IFluxState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -86,8 +85,6 @@ export const getApplications = async ({
|
||||
}: ActionContext<IFluxState, IRootState>): Promise<IApplication[] | undefined> => {
|
||||
console.debug('start to get applications for chat');
|
||||
state.status.getApplications = Status.Request;
|
||||
const currentApplication = state.application;
|
||||
console.debug('current application', currentApplication);
|
||||
try {
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: rootState?.user?.id,
|
||||
@@ -95,14 +92,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IHailuoConfig, IHailuoTask, IService } from
|
||||
import { Status } from '@/models/common';
|
||||
import { HAILUO_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IHailuoState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IHeadshotsConfig, IHeadshotsTask, IService }
|
||||
import { Status } from '@/models/common';
|
||||
import { HEADSHOTS_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IHeadshotsState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IKlingConfig, IKlingTask, IService } from '@
|
||||
import { Status } from '@/models/common';
|
||||
import { KLING_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IKlingState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, ILumaConfig, ILumaTask, IService } from '@/m
|
||||
import { Status } from '@/models/common';
|
||||
import { LUMA_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<ILumaState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -96,14 +95,6 @@ export const getApplications = async ({
|
||||
state.status.getApplications = Status.Success;
|
||||
console.debug('get applications success', applications.items);
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IMidjourneyConfig, IMidjourneyTask, IService
|
||||
import { Status } from '@/models/common';
|
||||
import { MIDJOURNEY_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IPikaConfig, IPikaTask, IService } from '@/m
|
||||
import { Status } from '@/models/common';
|
||||
import { PIKA_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IPikaState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, IQrartConfig, IQrartTask, IService } from '@
|
||||
import { Status } from '@/models/common';
|
||||
import { QRART_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IQrartState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IApplication, ICredential, ISunoConfig, ISunoTask, IService } from '@/m
|
||||
import { Status } from '@/models/common';
|
||||
import { SUNO_SERVICE_ID } from '@/constants';
|
||||
import { mergeAndSortLists } from '@/utils/merge';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<ISunoState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
@@ -95,14 +94,6 @@ export const getApplications = async ({
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
|
||||
Reference in new issue
Block a user