mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
sideload wip, websockets, styling, multiple todos (#2865)
* sideload wip, websockets, styling, multiple todos * sideload * misc backend updates * chore: comments * prep for license and instructions display * comment for Matt * s9pk updates and 040 sdk * fix dependency error for actions * 0.4.0-beta.1 * beta.2 --------- Co-authored-by: Aiden McClelland <me@drbonez.dev> Co-authored-by: waterplea <alexander@inkin.ru> Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { DataUrl, Manifest, MerkleArchiveCommitment } from "../osBindings"
|
||||
import {
|
||||
DataUrl,
|
||||
DependencyMetadata,
|
||||
Manifest,
|
||||
MerkleArchiveCommitment,
|
||||
PackageId,
|
||||
} from "../osBindings"
|
||||
import { ArrayBufferReader, MerkleArchive } from "./merkleArchive"
|
||||
import mime from "mime-types"
|
||||
import { DirectoryContents } from "./merkleArchive/directoryContents"
|
||||
import { FileContents } from "./merkleArchive/fileContents"
|
||||
|
||||
const magicAndVersion = new Uint8Array([59, 59, 2])
|
||||
|
||||
@@ -65,4 +73,63 @@ export class S9pk {
|
||||
).toString("base64")
|
||||
)
|
||||
}
|
||||
|
||||
async dependencyMetadataFor(id: PackageId) {
|
||||
const entry = this.archive.contents.getPath([
|
||||
"dependencies",
|
||||
id,
|
||||
"metadata.json",
|
||||
])
|
||||
if (!entry) return null
|
||||
return JSON.parse(
|
||||
new TextDecoder().decode(await entry.verifiedFileContents()),
|
||||
) as { title: string }
|
||||
}
|
||||
|
||||
async dependencyIconFor(id: PackageId) {
|
||||
const dir = this.archive.contents.getPath(["dependencies", id])
|
||||
if (!dir || !(dir.contents instanceof DirectoryContents)) return null
|
||||
const iconName = Object.keys(dir.contents.contents).find(
|
||||
(name) =>
|
||||
name.startsWith("icon.") &&
|
||||
(mime.contentType(name) || null)?.startsWith("image/"),
|
||||
)
|
||||
if (!iconName) return null
|
||||
return (
|
||||
`data:${mime.contentType(iconName)};base64,` +
|
||||
Buffer.from(
|
||||
await dir.contents.getPath([iconName])!.verifiedFileContents(),
|
||||
).toString("base64")
|
||||
)
|
||||
}
|
||||
|
||||
async dependencyMetadata(): Promise<Record<PackageId, DependencyMetadata>> {
|
||||
return Object.fromEntries(
|
||||
await Promise.all(
|
||||
Object.entries(this.manifest.dependencies).map(async ([id, info]) => [
|
||||
id,
|
||||
{
|
||||
...(await this.dependencyMetadataFor(id)),
|
||||
icon: await this.dependencyIconFor(id),
|
||||
description: info.description,
|
||||
optional: info.optional,
|
||||
},
|
||||
]),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
async instructions(): Promise<string> {
|
||||
const file = this.archive.contents.getPath(["instructions.md"])
|
||||
if (!file || !(file.contents instanceof FileContents))
|
||||
throw new Error("instructions.md not found in archive")
|
||||
return new TextDecoder().decode(await file.verifiedFileContents())
|
||||
}
|
||||
|
||||
async license(): Promise<string> {
|
||||
const file = this.archive.contents.getPath(["LICENSE.md"])
|
||||
if (!file || !(file.contents instanceof FileContents))
|
||||
throw new Error("instructions.md not found in archive")
|
||||
return new TextDecoder().decode(await file.verifiedFileContents())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user