Skip to content

Commit

Permalink
refa: update API versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 14, 2024
1 parent 0ebe4f2 commit 0bc7855
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/core/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<html>
<head>
<script>
window.base64ToArrayBuffer = function (base64) {
window.base64ToUint8Array = function (base64) {
const binary = atob(base64.replace(/\\s/g, ''))
const buffer = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) {
buffer[i] = binary.charCodeAt(i)
}
return buffer
return buffer.buffer
}

window.loadImage = function (id, base64) {
Expand All @@ -16,7 +16,7 @@
image.id = id
image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight })
image.onerror = reject
const blob = new Blob([base64ToArrayBuffer(base64)])
const blob = new Blob([base64ToUint8Array(base64)])
image.src = URL.createObjectURL(blob)
document.body.appendChild(image)
})
Expand Down
11 changes: 6 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
"koishi": "^4.17.2"
},
"devDependencies": {
"@types/node": "^20.10.2",
"atsc": "^2.0.1",
"koishi": "^4.17.2",
"typescript": "^5.3.2",
"undios-proxy-agent": "^0.2.0"
"@cordisjs/plugin-http": "^0.6.1",
"@cordisjs/plugin-proxy-agent": "^0.3.3",
"@types/node": "^22.1.0",
"atsc": "^2.1.0",
"koishi": "^4.17.11",
"typescript": "^5.5.3"
},
"dependencies": {
"@koishijs/canvas": "^0.2.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CanvasService, { Canvas, CanvasRenderingContext2D, Image } from '@koishijs/canvas'
import { arrayBufferToBase64, Context } from 'koishi'
import { Binary, Context } from 'koishi'
import { Page } from 'puppeteer-core'
import { resolve } from 'path'
import { pathToFileURL } from 'url'
Expand Down Expand Up @@ -118,11 +118,11 @@ class ImageElement extends BaseElement implements Image {
}
if (typeof this.source === 'string') {
const file = await this.ctx.http.file(this.source)
base64 = arrayBufferToBase64(file.data)
base64 = Binary.toBase64(file.data)
} else if (Buffer.isBuffer(this.source)) {
base64 = this.source.toString('base64')
} else {
base64 = arrayBufferToBase64(this.source)
base64 = Binary.toBase64(this.source)
}
const size = await this.page.evaluate(`loadImage(${JSON.stringify(this.id)}, ${JSON.stringify(base64)})`) as any
this.naturalWidth = size.width
Expand Down Expand Up @@ -164,7 +164,7 @@ export default class extends CanvasService {
].join('\n'))
return new CanvasElement(this.page, name, width, height)
} catch (err) {
console.log(err)
this.ctx.logger('puppeteer').warn(err)
throw err
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import puppeteer, { Browser, ElementHandle, Page } from 'puppeteer-core'
import find from 'puppeteer-finder'

Check failure on line 2 in packages/core/src/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'puppeteer-finder' or its corresponding type declarations.
import {} from 'undios-proxy-agent'
import {} from '@cordisjs/plugin-proxy-agent'
import { Context, h, hyphenate, Schema, Service } from 'koishi'
import { SVG, SVGOptions } from './svg'
import Canvas from './canvas'
Expand Down
2 changes: 1 addition & 1 deletion packages/finder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function findChromes() {
* @returns executable chrome full path
* @throws
* if no executable chrome find, ERROR_NO_INSTALLATIONS_FOUND will be throw
* if platform is not one if ['win32','darwin','linux','android'], ERROR_PLATFORM_NOT_SUPPORT will be throw
* if platform is not one if `win32`, `darwin`, `linux`, `android`, ERROR_PLATFORM_NOT_SUPPORT will be throw
*/
export = function findChrome() {

Check failure on line 27 in packages/finder/src/index.ts

View workflow job for this annotation

GitHub Actions / build

Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
const installations = findChromes()
Expand Down

0 comments on commit 0bc7855

Please sign in to comment.