This commit is contained in:
HCode authored and GitHub committed 2025-02-19 15:01:06 +00:00
1 parent 1203ef569b
commit 5d8902e566
40 files changed
+2416 -1

No files matched your search

+2
View File
@@ -5,6 +5,7 @@ import { IChatdocState } from '../chatdoc/models';
import { IQrartState } from '../qrart/models';
import { ILumaState } from '../luma/models';
import { IPikaState } from '../pika/models';
import { IFluxState } from '../flux/models';
import { IHailuoState } from '../hailuo/models';
import { IHeadshotsState } from '../headshots/models';
import { ISunoState } from '../suno/models';
@@ -36,6 +37,7 @@ export interface IRootState extends ICommonState {
qrart: IQrartState;
luma: ILumaState;
pika: IPikaState;
flux: IFluxState;
hailuo: IHailuoState;
headshots: IHeadshotsState;
suno: ISunoState;
+175
View File
@@ -0,0 +1,175 @@
import { applicationOperator, fluxOperator, serviceOperator } from '@/operators';
import { IFluxState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IFluxConfig, IFluxTask, IService, IApplicationType } from '@/models';
import { Status } from '@/models/common';
import { FLUX_SERVICE_ID } from '@/constants';
import { mergeAndSortLists } from '@/utils/merge';
export const resetAll = ({ commit }: ActionContext<IFluxState, 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: IFluxConfig) => {
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<IFluxState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for flux');
return new Promise((resolve, reject) => {
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: FLUX_SERVICE_ID
})
.then((response) => {
console.debug('get applications success', response?.data);
state.status.getApplications = Status.Success;
// 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);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
} else {
console.debug('set application with null', response.data.items?.[0]);
commit('setApplication', response.data.items?.[0]);
}
resolve(response.data.items);
console.debug('save application success', response.data.items[0]);
})
.catch((error) => {
state.status.getApplications = Status.Error;
reject(error);
});
});
};
export const setTasks = ({ commit }: any, payload: any) => {
commit('setTasks', payload);
};
export const setTasksItems = ({ commit }: any, payload: IFluxTask[]) => {
commit('setTasksItems', payload);
};
export const setTasksTotal = ({ commit }: any, payload: number) => {
commit('setTasksTotal', payload);
};
export const setTasksActive = ({ commit }: any, payload: IFluxTask) => {
commit('setTasksActive', payload);
};
export const getService = async ({ commit, state }: ActionContext<IFluxState, IRootState>): Promise<IService> => {
return new Promise((resolve, reject) => {
console.debug('start to get service for flux');
state.status.getService = Status.Request;
serviceOperator
.get(FLUX_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, rootState }: ActionContext<IFluxState, IRootState>,
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<IFluxTask[]> => {
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');
}
fluxOperator
.tasks(
{
userId: rootState?.user?.id,
createdAtMin,
createdAtMax,
type: 'images'
},
{
token
}
)
.then((response) => {
console.debug('get videos tasks success', response.data.items);
// merge with existing tasks
const existingItems = state?.tasks?.items || [];
console.debug('existing items', existingItems);
const newItems = response.data.items || [];
console.debug('new items', newItems);
// sort and de-duplicate using created_at
const mergedItems = mergeAndSortLists(existingItems, newItems);
commit('setTasksItems', mergedItems);
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
};
+14
View File
@@ -0,0 +1,14 @@
import { Module } from 'vuex';
import { IFluxState } from './models';
import actions from './actions';
import mutations from './mutations';
import state from './state';
export const flux: Module<IFluxState, any> = {
namespaced: true,
state,
mutations,
actions
};
export default flux;
+22
View File
@@ -0,0 +1,22 @@
import { IApplication, ICredential, IService, Status } from '@/models';
import { IFluxConfig, IFluxTask } from '@/models';
export interface IFluxState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: IFluxConfig | undefined;
tasks:
| {
items: IFluxTask[] | undefined;
total: number | undefined;
active: IFluxTask | undefined;
}
| undefined;
status: {
getService: Status;
getApplications: Status;
getTasks: Status;
};
}
+71
View File
@@ -0,0 +1,71 @@
import { IApplication, ICredential, IFluxConfig, IFluxTask, IService } from '@/models';
import { IFluxState } from './models';
export const resetAll = (state: IFluxState): void => {
state.service = undefined;
state.application = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
};
export const setService = (state: IFluxState, payload: IService): void => {
state.service = payload;
};
export const setCredential = (state: IFluxState, payload: ICredential): void => {
state.credential = payload;
};
export const setApplication = (state: IFluxState, payload: IApplication): void => {
state.application = payload;
};
export const setApplications = (state: IFluxState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setConfig = (state: IFluxState, payload: IFluxConfig): void => {
state.config = payload;
};
export const setTasksItems = (state: IFluxState, payload: IFluxTask[]): void => {
const newPayload = {
...state.tasks,
items: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksTotal = (state: IFluxState, payload: number): void => {
const newPayload = {
...state.tasks,
total: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksActive = (state: IFluxState, payload: IFluxTask): void => {
const newPayload = {
...state.tasks,
active: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasks = (state: IFluxState, payload: any): void => {
state.tasks = payload;
};
export default {
setTasks,
setApplication,
setApplications,
setConfig,
setCredential,
setService,
setTasksActive,
setTasksItems,
setTasksTotal,
resetAll
};
+1
View File
@@ -0,0 +1 @@
export default ['flux.credential', 'flux.application'];
+18
View File
@@ -0,0 +1,18 @@
import { IFluxState } from './models';
import { Status } from '@/models';
export default (): IFluxState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: undefined,
credential: undefined,
config: undefined,
status: {
getService: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};
};
+4
View File
@@ -6,6 +6,7 @@ import chatdoc from './chatdoc';
import qrart from './qrart';
import luma from './luma';
import pika from './pika';
import flux from './flux';
import hailuo from './hailuo';
import headshots from './headshots';
import suno from './suno';
@@ -16,6 +17,7 @@ import persistChatdoc from './chatdoc/persist';
import persistQrart from './qrart/persist';
import persistLuma from './luma/persist';
import persistPika from './pika/persist';
import persistFlux from './flux/persist';
import persistHailuo from './hailuo/persist';
import persistHeadshots from './headshots/persist';
import persistSuno from './suno/persist';
@@ -29,6 +31,7 @@ const store = createStore({
qrart: qrart,
luma: luma,
pika: pika,
flux: flux,
hailuo: hailuo,
headshots: headshots,
suno: suno,
@@ -44,6 +47,7 @@ const store = createStore({
...persistQrart,
...persistLuma,
...persistPika,
...persistFlux,
...persistHailuo,
...persistHeadshots,
...persistSuno