Add Suno pagination (#169)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2025-02-07 23:52:05 +08:00
1 parent ddb8cc2ea1
commit 5d91f2699a
44 files changed
+1148 -942

No files matched your search

+20 -4
View File
@@ -5,6 +5,7 @@ import { IRootState } from '../common/models';
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService, Song, IApplicationType } from '@/models';
import { Status } from '@/models/common';
import { SUNO_SERVICE_ID } from '@/constants';
import { mergeAndSortLists } from '@/utils/merge';
export const resetAll = ({ commit }: ActionContext<ISunoState, IRootState>): void => {
commit('resetAll');
@@ -117,10 +118,15 @@ export const getService = async ({ commit, state }: ActionContext<ISunoState, IR
export const getTasks = async (
{ commit, state, rootState }: ActionContext<ISunoState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<ISunoTask[]> => {
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
console.debug('start to get tasks', offset, limit, createdAtMax, createdAtMin);
const credential = state.credential;
const token = credential?.token;
if (!token) {
@@ -129,7 +135,10 @@ export const getTasks = async (
sunoOperator
.tasks(
{
userId: rootState?.user?.id
userId: rootState?.user?.id,
createdAtMin,
createdAtMax,
type: 'audios'
},
{
token
@@ -137,7 +146,14 @@ export const getTasks = async (
)
.then((response) => {
console.debug('get imagine tasks success', response.data.items);
commit('setTasksItems', 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);
})
+1 -1
View File
@@ -1 +1 @@
export default ['suno.credential', 'suno.application', 'suno.tasks'];
export default ['suno.credential', 'suno.application'];