Add hailuo (#168)

This commit is contained in:
HCode authored and GitHub committed 2025-02-06 19:06:11 +08:00
1 parent 76313da5b1
commit d3251fa84e
138 files changed
+9422 -3253

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 { IHailuoState } from '../hailuo/models';
import { IHeadshotsState } from '../headshots/models';
import { ISunoState } from '../suno/models';
@@ -35,6 +36,7 @@ export interface IRootState extends ICommonState {
qrart: IQrartState;
luma: ILumaState;
pika: IPikaState;
hailuo: IHailuoState;
headshots: IHeadshotsState;
suno: ISunoState;
}
+160
View File
@@ -0,0 +1,160 @@
import { applicationOperator, hailuoOperator, serviceOperator } from '@/operators';
import { IHailuoState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IHailuoConfig, IHailuoTask, IService, IApplicationType } from '@/models';
import { Status } from '@/models/common';
import { HAILUO_SERVICE_ID } from '@/constants';
export const resetAll = ({ commit }: ActionContext<IHailuoState, 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: IHailuoConfig) => {
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<IHailuoState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for hailuo');
return new Promise((resolve, reject) => {
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: HAILUO_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: IHailuoTask[]) => {
commit('setTasksItems', payload);
};
export const setTasksTotal = ({ commit }: any, payload: number) => {
commit('setTasksTotal', payload);
};
export const setTasksActive = ({ commit }: any, payload: IHailuoTask) => {
commit('setTasksActive', payload);
};
export const getService = async ({ commit, state }: ActionContext<IHailuoState, IRootState>): Promise<IService> => {
return new Promise((resolve, reject) => {
console.debug('start to get service for hailuo');
state.status.getService = Status.Request;
serviceOperator
.get(HAILUO_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<IHailuoState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
): Promise<IHailuoTask[]> => {
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');
}
hailuoOperator
.tasks(
{
userId: rootState?.user?.id,
type: 'videos'
},
{
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
};
+14
View File
@@ -0,0 +1,14 @@
import { Module } from 'vuex';
import { IHailuoState } from './models';
import actions from './actions';
import mutations from './mutations';
import state from './state';
export const hailuo: Module<IHailuoState, any> = {
namespaced: true,
state,
mutations,
actions
};
export default hailuo;
+22
View File
@@ -0,0 +1,22 @@
import { IApplication, ICredential, IService, Status } from '@/models';
import { IHailuoConfig, IHailuoTask } from '@/models';
export interface IHailuoState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: IHailuoConfig | undefined;
tasks:
| {
items: IHailuoTask[] | undefined;
total: number | undefined;
active: IHailuoTask | undefined;
}
| undefined;
status: {
getService: Status;
getApplications: Status;
getTasks: Status;
};
}
+71
View File
@@ -0,0 +1,71 @@
import { IApplication, ICredential, IHailuoConfig, IHailuoTask, IService } from '@/models';
import { IHailuoState } from './models';
export const resetAll = (state: IHailuoState): void => {
state.service = undefined;
state.application = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
};
export const setService = (state: IHailuoState, payload: IService): void => {
state.service = payload;
};
export const setCredential = (state: IHailuoState, payload: ICredential): void => {
state.credential = payload;
};
export const setApplication = (state: IHailuoState, payload: IApplication): void => {
state.application = payload;
};
export const setApplications = (state: IHailuoState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setConfig = (state: IHailuoState, payload: IHailuoConfig): void => {
state.config = payload;
};
export const setTasksItems = (state: IHailuoState, payload: IHailuoTask[]): void => {
const newPayload = {
...state.tasks,
items: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksTotal = (state: IHailuoState, payload: number): void => {
const newPayload = {
...state.tasks,
total: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksActive = (state: IHailuoState, payload: IHailuoTask): void => {
const newPayload = {
...state.tasks,
active: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasks = (state: IHailuoState, 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 ['hailuo.credential', 'hailuo.application', 'hailuo.tasks'];
+18
View File
@@ -0,0 +1,18 @@
import { IHailuoState } from './models';
import { Status } from '@/models';
export default (): IHailuoState => {
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 hailuo from './hailuo';
import headshots from './headshots';
import suno from './suno';
import root from './common';
@@ -15,6 +16,7 @@ import persistChatdoc from './chatdoc/persist';
import persistQrart from './qrart/persist';
import persistLuma from './luma/persist';
import persistPika from './pika/persist';
import persistHailuo from './hailuo/persist';
import persistHeadshots from './headshots/persist';
import persistSuno from './suno/persist';
import persistRoot from './common/persist';
@@ -27,6 +29,7 @@ const store = createStore({
qrart: qrart,
luma: luma,
pika: pika,
hailuo: hailuo,
headshots: headshots,
suno: suno,
chatdoc: chatdoc
@@ -41,6 +44,7 @@ const store = createStore({
...persistQrart,
...persistLuma,
...persistPika,
...persistHailuo,
...persistHeadshots,
...persistSuno
]