Skip to content

Commit

Permalink
Typescript Quickfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsRiprod committed Oct 30, 2024
1 parent 7103801 commit 20bf403
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions DeskThingServer/src/main/handlers/authHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ let callBackPort: number

function handleCallback(req: http.IncomingMessage, res: http.ServerResponse): void {
const parsedUrl = url.parse(req.url || '', true)

dataListener.asyncEmit(
MESSAGE_TYPES.LOGGING,
`AUTH: Received callback request for ${parsedUrl.pathname}`
)

const urlParts = parsedUrl.pathname?.split('/').filter(Boolean)

if (!urlParts || urlParts.length < 2) {
Expand Down
29 changes: 17 additions & 12 deletions DeskThingServer/src/main/services/apps/appInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,25 @@ export async function handleZipFromUrl(zipUrlPath: string, reply): Promise<AppRe
const response2 = response.clone()
const contentLength = Number(response.headers.get('content-length'))
let receivedLength = 0
const reader = response2.body.getReader()
const chunks = []
const reader = response2.body?.getReader()
if (!reader) {
throw new Error('Failed to get reader from response body')
}
const chunks: Uint8Array[] = []
let lastProgress = 0

while (true) {
const { done, value } = await reader.read()
if (done) break
chunks.push(value)
receivedLength += value.length
const progress = Math.round((receivedLength / contentLength) * 100)
if (progress > lastProgress) {
reply('logging', { status: true, data: `Downloading... ${progress}%`, final: false })
lastProgress = progress
let done = false
while (!done) {
const result = await reader.read()
done = result.done
if (!done) {
chunks.push(result.value as Uint8Array)
receivedLength += result.value?.length || 0
const progress = Math.round((receivedLength / contentLength) * 100)
if (progress > lastProgress) {
reply('logging', { status: true, data: `Downloading... ${progress}%`, final: false })
lastProgress = progress
}
}
}

Expand Down Expand Up @@ -225,7 +231,6 @@ export async function handleZipFromUrl(zipUrlPath: string, reply): Promise<AppRe
}
}
}

/**
* Runs an app by its name.
*
Expand Down

0 comments on commit 20bf403

Please sign in to comment.