feat: wire bark battle platform loop
Some checks failed
CI / verify (pull_request) Has been cancelled
Some checks failed
CI / verify (pull_request) Has been cancelled
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import type {
|
||||
BarkBattleDraftConfig,
|
||||
BarkBattleDraftCreateRequest,
|
||||
BarkBattlePublishedConfig,
|
||||
BarkBattleWorkPublishRequest,
|
||||
} from '../../../packages/shared/src/contracts/barkBattle';
|
||||
import {
|
||||
type ApiRequestOptions,
|
||||
type ApiRetryOptions,
|
||||
requestJson,
|
||||
} from '../apiClient';
|
||||
|
||||
const BARK_BATTLE_CREATION_API_BASE = '/api/creation/bark-battle';
|
||||
|
||||
const BARK_BATTLE_CREATION_WRITE_RETRY: ApiRetryOptions = {
|
||||
maxRetries: 1,
|
||||
baseDelayMs: 120,
|
||||
maxDelayMs: 360,
|
||||
retryUnsafeMethods: true,
|
||||
};
|
||||
|
||||
export type BarkBattleCreationRequestOptions = Pick<
|
||||
ApiRequestOptions,
|
||||
| 'authImpact'
|
||||
| 'skipRefresh'
|
||||
| 'notifyAuthStateChange'
|
||||
| 'clearAuthOnUnauthorized'
|
||||
>;
|
||||
|
||||
export function createBarkBattleDraft(
|
||||
payload: BarkBattleDraftCreateRequest,
|
||||
options: BarkBattleCreationRequestOptions = {},
|
||||
) {
|
||||
return requestJson<BarkBattleDraftConfig>(
|
||||
`${BARK_BATTLE_CREATION_API_BASE}/drafts`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
'创建汪汪声浪大作战草稿失败',
|
||||
{
|
||||
retry: BARK_BATTLE_CREATION_WRITE_RETRY,
|
||||
authImpact: options.authImpact,
|
||||
skipRefresh: options.skipRefresh,
|
||||
notifyAuthStateChange: options.notifyAuthStateChange,
|
||||
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function publishBarkBattleWork(
|
||||
payload: BarkBattleWorkPublishRequest,
|
||||
options: BarkBattleCreationRequestOptions = {},
|
||||
) {
|
||||
return requestJson<BarkBattlePublishedConfig>(
|
||||
`${BARK_BATTLE_CREATION_API_BASE}/works/publish`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
'发布汪汪声浪大作战作品失败',
|
||||
{
|
||||
retry: BARK_BATTLE_CREATION_WRITE_RETRY,
|
||||
authImpact: options.authImpact,
|
||||
skipRefresh: options.skipRefresh,
|
||||
notifyAuthStateChange: options.notifyAuthStateChange,
|
||||
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export const barkBattleCreationClient = {
|
||||
createDraft: createBarkBattleDraft,
|
||||
publish: publishBarkBattleWork,
|
||||
};
|
||||
Reference in New Issue
Block a user