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 -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
}
};