Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Dec 19, 2024
1 parent 40dbe67 commit 4849c46
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion xmcl
16 changes: 10 additions & 6 deletions xmcl-runtime/instanceIO/XUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LauncherApp } from '../app/LauncherApp'
import { missing } from '../util/fs'
import { isValidUrl, joinUrl } from '../util/url'
import { ZipTask } from '../util/zip'
import { Readable } from 'stream'

export class XUpdateService extends AbstractService implements IXUpdateService {
constructor(@Inject(LauncherAppKey) app: LauncherApp,
Expand Down Expand Up @@ -78,18 +79,21 @@ export class XUpdateService extends AbstractService implements IXUpdateService {

allHeaders['content-type'] = useJson ? 'application/json' : 'application/zip'

const res = await request(instance.fileApi, {
const res = await this.app.fetch(instance.fileApi, {
method: 'POST',
headers: allHeaders,
body: useJson ? JSON.stringify(manifest) : createReadStream(tempZipFile),
body: useJson ? JSON.stringify(manifest) : Readable.toWeb(createReadStream(tempZipFile)) as any,
})

if (res.statusCode !== 201) {
this.error(new Error(`Fail to upload ${instancePath} to ${instance.fileApi} as server rejected. Status code: ${res.statusCode}, ${res.body}`))
throw new InstanceIOException({ type: 'instanceSetManifestFailed', httpBody: res.body, statusCode: res.statusCode })
if (res.status !== 201) {
this.error(new Error(`Fail to upload ${instancePath} to ${instance.fileApi} as server rejected. Status code: ${res.status}, ${res.body}`))
throw new InstanceIOException({ type: 'instanceSetManifestFailed', httpBody: res.body, statusCode: res.status })
}

for await (const _ of res.body) { /* skip */ }
if (res.body) {
const readable = Readable.from(res.body as any)
for await (const _ of readable) { /* skip */ }
}

this.log(`Uploaded instance ${instancePath} to ${instance.fileApi}. Took ${Date.now() - start}ms.`)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/network/dispatchers/ErrorDecorateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dispatcher } from 'undici'
import { DispatchHandler } from './dispatcher'

export class ErrorDecorateHandler extends DispatchHandler {
constructor(handler: Dispatcher.DispatchHandlers, private options: Dispatcher.DispatchOptions,
constructor(handler: Dispatcher.DispatchHandler, private options: Dispatcher.DispatchOptions,
private _onError: (err: Error) => void) {
super(handler)
}
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/network/dispatchers/NetworkAgent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Socket } from 'net'
import { Agent, Client, Dispatcher, RetryHandler, buildConnector, errors, util } from 'undici'

type DispatchHandlers = Dispatcher.DispatchHandlers
type DispatchHandlers = Dispatcher.DispatchHandler
const { InvalidArgumentError, RequestAbortedError } = errors

function defaultProtocolPort(protocol: string) {
Expand Down
6 changes: 3 additions & 3 deletions xmcl-runtime/network/dispatchers/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface DispatchInterceptor {
(options: Dispatcher.DispatchOptions): void
}

export class DispatchHandler implements Dispatcher.DispatchHandlers {
constructor(protected handler: Dispatcher.DispatchHandlers) {
export class DispatchHandler implements Dispatcher.DispatchHandler {
constructor(protected handler: Dispatcher.DispatchHandler) {
}

/** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
Expand Down Expand Up @@ -61,7 +61,7 @@ export class InteroperableDispatcher extends Dispatcher {
super()
}

dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean {
dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean {
const process = async () => {
for (const interceptor of this.interceptors) {
await interceptor(options)
Expand Down

0 comments on commit 4849c46

Please sign in to comment.