1 parent
2e0665f09c
commit
6be9299532
42 files changed
+2342
-5
No files matched your search
@@ -3,6 +3,7 @@ import { IMidjourneyState } from '../midjourney/models';
|
||||
import { IChatState } from '../chat/models';
|
||||
import { IChatdocState } from '../chatdoc/models';
|
||||
import { IQrartState } from '../qrart/models';
|
||||
import { ILumaState } from '../luma/models';
|
||||
import { ISunoState } from '../suno/models';
|
||||
|
||||
export interface ISetting {}
|
||||
@@ -29,5 +30,6 @@ export interface IRootState extends ICommonState {
|
||||
chat: IChatState;
|
||||
chatdoc: IChatdocState;
|
||||
qrart: IQrartState;
|
||||
luma: ILumaState;
|
||||
suno: ISunoState;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import chatState from '../chat/state';
|
||||
import midjourneyState from '../midjourney/state';
|
||||
import chatdocState from '../chatdoc/state';
|
||||
import qrartState from '../qrart/state';
|
||||
import lumaState from '../luma/state';
|
||||
import sunoState from '../suno/state';
|
||||
|
||||
export default (): IRootState => {
|
||||
@@ -25,6 +26,7 @@ export default (): IRootState => {
|
||||
chat: chatState(),
|
||||
midjourney: midjourneyState(),
|
||||
qrart: qrartState(),
|
||||
luma: lumaState(),
|
||||
suno: sunoState()
|
||||
};
|
||||
};
|
||||
+12
-1
@@ -4,12 +4,14 @@ import midjourney from './midjourney';
|
||||
import chat from './chat';
|
||||
import chatdoc from './chatdoc';
|
||||
import qrart from './qrart';
|
||||
import luma from './luma';
|
||||
import suno from './suno';
|
||||
import root from './common';
|
||||
import persistChat from './chat/persist';
|
||||
import persistMidjourney from './midjourney/persist';
|
||||
import persistChatdoc from './chatdoc/persist';
|
||||
import persistQrart from './qrart/persist';
|
||||
import persistLuma from './luma/persist';
|
||||
import persistSuno from './suno/persist';
|
||||
import persistRoot from './common/persist';
|
||||
|
||||
@@ -19,12 +21,21 @@ const store = createStore({
|
||||
midjourney: midjourney,
|
||||
chat: chat,
|
||||
qrart: qrart,
|
||||
luma: luma,
|
||||
suno: suno,
|
||||
chatdoc: chatdoc
|
||||
},
|
||||
plugins: [
|
||||
createPersistedState({
|
||||
paths: [...persistRoot, ...persistChat, ...persistMidjourney, ...persistChatdoc, ...persistQrart, ...persistSuno]
|
||||
paths: [
|
||||
...persistRoot,
|
||||
...persistChat,
|
||||
...persistMidjourney,
|
||||
...persistChatdoc,
|
||||
...persistQrart,
|
||||
...persistLuma,
|
||||
...persistSuno
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import { applicationOperator, lumaOperator, serviceOperator } from '@/operators';
|
||||
import { ILumaState } from './models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState } from '../common/models';
|
||||
import { IApplication, ICredential, ILumaConfig, ILumaTask, IService, IApplicationType } from '@/models';
|
||||
import { Status } from '@/models/common';
|
||||
import { LUMA_SERVICE_ID } from '@/constants';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<ILumaState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setConfig = ({ commit }: any, payload: ILumaConfig) => {
|
||||
commit('setConfig', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
export const setApplication = ({ commit }: any, payload: IApplication[]) => {
|
||||
commit('setApplication', payload);
|
||||
};
|
||||
|
||||
export const getApplications = async ({
|
||||
commit,
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<ILumaState, IRootState>): Promise<IApplication[]> => {
|
||||
console.debug('start to get applications for qrart');
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getApplications = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
user_id: rootState?.user?.id,
|
||||
service_id: LUMA_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
console.debug('get applications success', response?.data);
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', response.data.items);
|
||||
// check if there is any application with 'Period' type
|
||||
const application = response.data.items?.find((application) => application?.type === IApplicationType.PERIOD);
|
||||
const application2 = response.data.items?.find((application) => application?.type === IApplicationType.USAGE);
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('get applications error', error);
|
||||
state.status.getApplications = Status.Error;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const setTasks = ({ commit }: any, payload: any) => {
|
||||
commit('setTasks', payload);
|
||||
};
|
||||
|
||||
export const setTasksItems = ({ commit }: any, payload: ILumaTask[]) => {
|
||||
commit('setTasksItems', payload);
|
||||
};
|
||||
|
||||
export const setTasksTotal = ({ commit }: any, payload: number) => {
|
||||
commit('setTasksTotal', payload);
|
||||
};
|
||||
|
||||
export const setTasksActive = ({ commit }: any, payload: ILumaTask) => {
|
||||
commit('setTasksActive', payload);
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<ILumaState, IRootState>): Promise<IService> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for luma');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(LUMA_SERVICE_ID)
|
||||
.then((response) => {
|
||||
state.status.getService = Status.Success;
|
||||
commit('setService', response.data);
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
state.status.getService = Status.Error;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const getTasks = async (
|
||||
{ commit, state }: ActionContext<ILumaState, IRootState>,
|
||||
{ offset, limit }: { offset?: number; limit?: number }
|
||||
): Promise<ILumaTask[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get tasks', offset, limit);
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return reject('no token');
|
||||
}
|
||||
lumaOperator
|
||||
.tasks(
|
||||
{
|
||||
applicationId: state.application?.id
|
||||
},
|
||||
{
|
||||
token
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
console.debug('get imagine tasks success', response.data.items);
|
||||
commit('setTasksItems', response.data.items);
|
||||
commit('setTasksTotal', response.data.count);
|
||||
resolve(response.data.items);
|
||||
})
|
||||
.catch((error) => {
|
||||
return reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
setService,
|
||||
getService,
|
||||
resetAll,
|
||||
setCredential,
|
||||
setConfig,
|
||||
setApplication,
|
||||
getApplications,
|
||||
setTasks,
|
||||
setTasksItems,
|
||||
setTasksTotal,
|
||||
setTasksActive,
|
||||
getTasks
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from 'vuex';
|
||||
import { ILumaState } from './models';
|
||||
import actions from './actions';
|
||||
import mutations from './mutations';
|
||||
import state from './state';
|
||||
|
||||
export const luma: Module<ILumaState, any> = {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
};
|
||||
|
||||
export default luma;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { IApplication, ICredential, IService, Status } from '@/models';
|
||||
import { ILumaConfig, ILumaTask } from '@/models';
|
||||
|
||||
export interface ILumaState {
|
||||
application: IApplication | undefined;
|
||||
service: IService | undefined;
|
||||
credential: ICredential | undefined;
|
||||
config: ILumaConfig | undefined;
|
||||
tasks:
|
||||
| {
|
||||
items: ILumaTask[] | undefined;
|
||||
total: number | undefined;
|
||||
active: ILumaTask | undefined;
|
||||
}
|
||||
| undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplications: Status;
|
||||
getTasks: Status;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { IApplication, ICredential, ILumaConfig, ILumaTask, IService } from '@/models';
|
||||
import { ILumaState } from './models';
|
||||
|
||||
export const resetAll = (state: ILumaState): void => {
|
||||
state.service = undefined;
|
||||
state.application = undefined;
|
||||
state.config = undefined;
|
||||
state.credential = undefined;
|
||||
state.tasks = undefined;
|
||||
};
|
||||
|
||||
export const setService = (state: ILumaState, payload: IService): void => {
|
||||
state.service = payload;
|
||||
};
|
||||
|
||||
export const setCredential = (state: ILumaState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setApplication = (state: ILumaState, payload: IApplication): void => {
|
||||
state.application = payload;
|
||||
};
|
||||
|
||||
export const setConfig = (state: ILumaState, payload: ILumaConfig): void => {
|
||||
state.config = payload;
|
||||
};
|
||||
|
||||
export const setTasksItems = (state: ILumaState, payload: ILumaTask[]): void => {
|
||||
const newPayload = {
|
||||
...state.tasks,
|
||||
items: payload
|
||||
} as typeof state.tasks;
|
||||
state.tasks = newPayload;
|
||||
};
|
||||
|
||||
export const setTasksTotal = (state: ILumaState, payload: number): void => {
|
||||
const newPayload = {
|
||||
...state.tasks,
|
||||
total: payload
|
||||
} as typeof state.tasks;
|
||||
state.tasks = newPayload;
|
||||
};
|
||||
|
||||
export const setTasksActive = (state: ILumaState, payload: ILumaTask): void => {
|
||||
const newPayload = {
|
||||
...state.tasks,
|
||||
active: payload
|
||||
} as typeof state.tasks;
|
||||
state.tasks = newPayload;
|
||||
};
|
||||
|
||||
export const setTasks = (state: ILumaState, payload: any): void => {
|
||||
state.tasks = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setTasks,
|
||||
setApplication,
|
||||
setConfig,
|
||||
setCredential,
|
||||
setService,
|
||||
setTasksActive,
|
||||
setTasksItems,
|
||||
setTasksTotal,
|
||||
resetAll
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export default ['luma.config', 'luma.credential', 'luma.application', 'luma.tasks'];
|
||||
@@ -0,0 +1,17 @@
|
||||
import { ILumaState } from './models';
|
||||
import { Status } from '@/models';
|
||||
|
||||
export default (): ILumaState => {
|
||||
return {
|
||||
service: undefined,
|
||||
application: undefined,
|
||||
tasks: undefined,
|
||||
credential: undefined,
|
||||
config: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplications: Status.None,
|
||||
getTasks: Status.None
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user