Add subscription support (#100)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2024-08-16 00:31:58 +08:00
1 parent 7688a1787e
commit 14b04fe54f
355 files changed
+9161 -7020

No files matched your search

+21 -15
View File
@@ -2,7 +2,7 @@ import { applicationOperator, chatOperator, serviceOperator } from '@/operators'
import { IRootState } from '../common/models';
import { ActionContext } from 'vuex';
import { IChatState } from './models';
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
import { IApplication, IApplicationType, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
import { CHAT_SERVICE_ID } from '@/constants';
export const resetAll = ({ commit }: ActionContext<IChatState, IRootState>): void => {
@@ -64,14 +64,14 @@ export const getService = async ({ commit, state }: ActionContext<IChatState, IR
});
};
export const getApplication = async ({
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<IChatState, IRootState>): Promise<IApplication> => {
}: ActionContext<IChatState, IRootState>): Promise<IApplication[]> => {
return new Promise((resolve, reject) => {
console.debug('start to get application for chat');
state.status.getApplication = Status.Request;
console.debug('start to get applications for chat');
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
@@ -79,17 +79,23 @@ export const getApplication = async ({
})
.then((response) => {
console.debug('get application success', response?.data);
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('save application success', response.data.items[0]);
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) => {
state.status.getApplication = Status.Error;
state.status.getApplications = Status.Error;
reject(error);
});
});
@@ -138,7 +144,7 @@ export default {
setService,
setCredential,
setApplication,
getApplication,
getApplications,
setConversation,
setConversations,
getConversations
+2 -1
View File
@@ -2,13 +2,14 @@ import { IApplication, IChatConversation, IChatModel, ICredential, IService, Sta
export interface IChatState {
model: IChatModel;
applications: IApplication[] | undefined;
application: IApplication | undefined;
service: IService | undefined;
conversations: IChatConversation[] | undefined;
credential: ICredential | undefined;
status: {
getService: Status;
getApplication: Status;
getApplications: Status;
getConversations: Status;
};
}
+6
View File
@@ -4,6 +4,7 @@ import { IChatState } from './models';
export const resetAll = (state: IChatState): void => {
state.application = undefined;
state.conversations = undefined;
state.applications = undefined;
state.credential = undefined;
state.service = undefined;
};
@@ -20,6 +21,10 @@ export const setApplication = (state: IChatState, payload: IApplication): void =
state.application = payload;
};
export const setApplications = (state: IChatState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setService = (state: IChatState, payload: IService): void => {
state.service = payload;
};
@@ -34,5 +39,6 @@ export default {
setCredential,
setConversations,
setApplication,
setApplications,
resetAll
};
+2 -1
View File
@@ -5,13 +5,14 @@ import { Status } from '@/models';
export default (): IChatState => {
return {
model: CHAT_MODEL_GPT_3_5,
applications: undefined,
application: undefined,
conversations: undefined,
service: undefined,
credential: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
getApplications: Status.None,
getConversations: Status.None
}
};
+21 -14
View File
@@ -4,6 +4,7 @@ import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import {
IApplication,
IApplicationType,
ICredential,
IMidjourneyPreset,
IMidjourneyTask,
@@ -39,32 +40,38 @@ export const setApplication = ({ commit }: any, payload: IApplication[]) => {
commit('setApplication', payload);
};
export const getApplication = async ({
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<IMidjourneyState, IRootState>): Promise<IApplication> => {
console.debug('start to get application for midjourney');
}: ActionContext<IMidjourneyState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for midjourney');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: MIDJOURNEY_SERVICE_ID
})
.then((response) => {
console.debug('get application success', response?.data);
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
commit('setCredential', credential);
resolve(response.data.items[0]);
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 application success', response.data.items[0]);
})
.catch((error) => {
state.status.getApplication = Status.Error;
state.status.getApplications = Status.Error;
reject(error);
});
});
@@ -133,7 +140,7 @@ export default {
setPreset,
setMode,
setApplication,
getApplication,
getApplications,
setTasks,
getTasks
};
+2 -1
View File
@@ -3,6 +3,7 @@ import { IApplication, ICredential, IMidjourneyPreset, IMidjourneyTask, IService
export interface IMidjourneyState {
service: IService | undefined;
application: IApplication | undefined;
applications: IApplication[] | undefined;
tasks:
| {
items: IMidjourneyTask[] | undefined;
@@ -13,7 +14,7 @@ export interface IMidjourneyState {
preset: IMidjourneyPreset;
status: {
getService: Status;
getApplication: Status;
getApplications: Status;
getTasks: Status;
};
}
+6
View File
@@ -3,6 +3,7 @@ import { IMidjourneyState } from './models';
export const resetAll = (state: IMidjourneyState): void => {
state.application = undefined;
state.applications = undefined;
state.preset = {};
state.tasks = {
items: undefined,
@@ -10,6 +11,10 @@ export const resetAll = (state: IMidjourneyState): void => {
};
};
export const setApplications = (state: IMidjourneyState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setService = (state: IMidjourneyState, payload: IService): void => {
state.service = payload;
};
@@ -32,6 +37,7 @@ export const setTasks = (state: IMidjourneyState, payload: any): void => {
export default {
setApplication,
setApplications,
setPreset,
setCredential,
setService,
+2 -1
View File
@@ -5,6 +5,7 @@ export default (): IMidjourneyState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: {
items: undefined,
total: undefined
@@ -13,7 +14,7 @@ export default (): IMidjourneyState => {
preset: {},
status: {
getService: Status.None,
getApplication: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};
+23 -18
View File
@@ -2,7 +2,7 @@ import { applicationOperator, qrartOperator, serviceOperator } from '@/operators
import { IQrartState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IQrartConfig, IQrartTask, IService } from '@/models';
import { IApplication, IApplicationType, ICredential, IQrartConfig, IQrartTask, IService } from '@/models';
import { Status } from '@/models/common';
import { QRART_SERVICE_ID } from '@/constants';
@@ -28,34 +28,39 @@ export const setApplication = ({ commit }: any, payload: IApplication[]) => {
commit('setApplication', payload);
};
export const getApplication = async ({
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<IQrartState, IRootState>): Promise<IApplication> => {
console.debug('start to get application for qrart');
}: ActionContext<IQrartState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for qrart');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: QRART_SERVICE_ID
})
.then((response) => {
console.debug('get application success', response?.data);
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('get credential success', credential);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('save application success', response.data.items[0]);
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 application error', error);
state.status.getApplication = Status.Error;
console.error('get applications error', error);
state.status.getApplications = Status.Error;
reject(error);
});
});
@@ -134,7 +139,7 @@ export default {
setCredential,
setConfig,
setApplication,
getApplication,
getApplications,
setTasks,
setTasksItems,
setTasksTotal,
+2 -1
View File
@@ -3,6 +3,7 @@ import { IQrartConfig, IQrartTask } from '@/models';
export interface IQrartState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: IQrartConfig | undefined;
@@ -15,7 +16,7 @@ export interface IQrartState {
| undefined;
status: {
getService: Status;
getApplication: Status;
getApplications: Status;
getTasks: Status;
};
}
+6
View File
@@ -4,6 +4,7 @@ import { IQrartState } from './models';
export const resetAll = (state: IQrartState): void => {
state.service = undefined;
state.application = undefined;
state.applications = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
@@ -13,6 +14,10 @@ export const setService = (state: IQrartState, payload: IService): void => {
state.service = payload;
};
export const setApplications = (state: IQrartState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setCredential = (state: IQrartState, payload: ICredential): void => {
state.credential = payload;
};
@@ -56,6 +61,7 @@ export const setTasks = (state: IQrartState, payload: any): void => {
export default {
setTasks,
setApplication,
setApplications,
setConfig,
setCredential,
setService,
+2 -1
View File
@@ -5,12 +5,13 @@ export default (): IQrartState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: undefined,
credential: undefined,
config: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};
+21 -14
View File
@@ -2,7 +2,7 @@ import { applicationOperator, sunoOperator, serviceOperator } from '@/operators'
import { ISunoState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService, Song } from '@/models';
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService, Song, IApplicationType } from '@/models';
import { Status } from '@/models/common';
import { SUNO_SERVICE_ID } from '@/constants';
@@ -28,30 +28,37 @@ export const setApplication = ({ commit }: any, payload: IApplication[]) => {
commit('setApplication', payload);
};
export const getApplication = async ({
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<ISunoState, IRootState>): Promise<IApplication> => {
console.debug('start to get application for suno');
}: ActionContext<ISunoState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for suno');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: SUNO_SERVICE_ID
})
.then((response) => {
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
commit('setCredential', credential);
resolve(response.data.items[0]);
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) => {
state.status.getApplication = Status.Error;
state.status.getApplications = Status.Error;
reject(error);
});
});
@@ -134,7 +141,7 @@ export default {
setCredential,
setConfig,
setApplication,
getApplication,
getApplications,
setTasks,
setTasksItems,
setTasksTotal,
+2 -19
View File
@@ -3,6 +3,7 @@ import { ISunoConfig, ISunoTask } from '@/models';
export interface ISunoState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: ISunoConfig | undefined;
@@ -16,25 +17,7 @@ export interface ISunoState {
audio: ISunoAudio | undefined;
status: {
getService: Status;
getApplication: Status;
getApplications: Status;
getTasks: Status;
};
}
// export interface PlayerState {
// audio?: HTMLAudioElement | undefined;
// loopType?: number;
// volume?: number;
// playList?: Song[] | undefined;
// showPlayList?: boolean;
// id?: string;
// url?: string;
// song?: Song | undefined;
// isPlaying?: boolean;
// isPause?: boolean;
// sliderInput?: boolean;
// ended?: boolean;
// muted?: boolean;
// currentTime?: number;
// duration?: number;
// }
+6 -98
View File
@@ -1,18 +1,19 @@
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService } from '@/models';
import { ISunoState } from './models';
// import { Song, SongUrl } from '@/models';
// const KEYS = {
// volume: 'PLAYER-VOLUME'
// };
export const resetAll = (state: ISunoState): void => {
state.service = undefined;
state.application = undefined;
state.applications = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
};
export const setApplications = (state: ISunoState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setService = (state: ISunoState, payload: IService): void => {
state.service = payload;
};
@@ -60,104 +61,11 @@ export const setAudio = (state: ISunoState, payload: any): void => {
export const setTasks = (state: ISunoState, payload: any): void => {
state.tasks = payload;
};
// // 歌曲播放的mutations方法
// // 播放器相关的 mutations
// export const setAudio = (state: RootState, audio: HTMLAudioElement): void => {
// state.player.audio = audio;
// };
// // 设置循环模式
// export const setLoopType = (state: RootState, loopType: number): void => {
// state.player.loopType = loopType;
// };
// // 设置音量
// export const setVolume = (state: RootState, volume: number): void => {
// state.player.volume = volume;
// state.player.audio.volume = volume / 100;
// localStorage.setItem(KEYS.volume, volume.toString());
// };
// // 设置播放列表
// export const setPlayList = (state: RootState, playList: Song[]): void => {
// state.player.playList = playList;
// };
// // 设置是否展示播放列表
// export const setShowPlayList = (state: RootState, showPlayList: boolean): void => {
// state.player.showPlayList = showPlayList;
// };
// // 设置歌曲ID
// export const setId = (state: RootState, id: string): void => {
// state.player.id = id;
// };
// // 设置歌曲URL
// export const setUrl = (state: RootState, url: string): void => {
// state.player.url = url;
// };
// // 设置歌曲
// export const setSong = (state: RootState, song: Song): void => {
// state.player.song = song;
// };
// // 设置歌曲正在播放
// export const setIsPlaying = (state: RootState, isPlaying: boolean): void => {
// state.player.isPlaying = isPlaying;
// };
// // 设置歌曲正在暂停
// export const setIsPause = (state: RootState, isPause: boolean): void => {
// state.player.isPause = isPause;
// };
// // 设置歌曲播放进度
// export const setSliderInput = (state: RootState, sliderInput: boolean): void => {
// state.player.sliderInput = sliderInput;
// };
// // 设置歌曲播放结束
// export const setEnded = (state: RootState, ended: boolean): void => {
// state.player.ended = ended;
// };
// // 设置歌曲静音
// export const setMuted = (state: RootState, muted: boolean): void => {
// state.player.muted = muted;
// state.player.audio.muted = muted;
// };
// // 设置歌曲播放当前时间
// export const setCurrentTime = (state: RootState, currentTime: number): void => {
// state.player.currentTime = currentTime;
// };
// // 设置歌曲总时长
// export const setDuration = (state: RootState, duration: number): void => {
// state.player.duration = duration;
// };
// // 将歌曲添加到播放列表
// export const pushPlayList = (state: RootState, { replace, list }: { replace: boolean; list: Song[] }): void => {
// if (replace) {
// state.player.playList = list;
// } else {
// list.forEach((song) => {
// if (state.player.playList.filter((s) => s.id == song.id).length <= 0) {
// state.player.playList.push(song);
// }
// });
// }
// };
// // 清空播放列表
// export const clearPlayList = (state: RootState): void => {
// state.player.url = '';
// state.player.id = '0';
// state.player.song = {} as Song;
// state.player.isPlaying = false;
// state.player.isPause = false;
// state.player.sliderInput = false;
// state.player.ended = false;
// state.player.muted = false;
// state.player.currentTime = 0;
// state.player.playList = [];
// state.player.showPlayList = false;
// state.player.audio.load();
// setTimeout(() => {
// state.player.duration = 0;
// }, 500);
// };
export default {
setTasks,
setApplication,
setApplications,
setConfig,
setCredential,
setService,
+2 -1
View File
@@ -5,6 +5,7 @@ export default (): ISunoState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: undefined,
audio: {
volume: 100
@@ -13,7 +14,7 @@ export default (): ISunoState => {
config: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};