This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adjusted endpoints for media conversion Adjusted MediaResponse type format Support for log files (partial) * code cleanup, fixes * more error checking * fix up message a bit * update documentation, errors * add min texture size check * Fix multiple upload of media files for conversion (Issue #15) --------- Co-authored-by: Nawias <[email protected]>
- Loading branch information
Showing
11 changed files
with
561 additions
and
374 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import JSZip, { JSZipObject } from "jszip"; | ||
import Config, { ConfigMetadata, parseConfig } from "./Config"; | ||
|
||
export type BundleIcons = { | ||
ctr?: Blob; | ||
cafe?: Blob; | ||
hac?: Blob; | ||
}; | ||
|
||
/* | ||
** Bundler class | ||
** Represents a bundle of files and configuration. | ||
*/ | ||
export default class Bundle { | ||
private file: File; | ||
|
||
private zip: JSZip | undefined; | ||
private config: Config | undefined; | ||
|
||
readonly ConfigName = "lovebrew.toml"; | ||
|
||
constructor(zip: File) { | ||
this.file = zip; | ||
} | ||
|
||
/** | ||
* Validates the bundle | ||
* @returns {Promise<boolean>} - Whether the file is a valid bundle. | ||
*/ | ||
public async validate(): Promise<boolean> { | ||
this.zip = await JSZip.loadAsync(this.file); | ||
|
||
const data = await this.zip.file(this.ConfigName)?.async("string"); | ||
|
||
if (data === undefined) { | ||
throw Error("Missing configuration file."); | ||
} | ||
|
||
this.config = parseConfig(data); | ||
|
||
const source = this.config.build.source; | ||
if (this.zip.file(new RegExp(`^${source}/.+`)).length === 0) { | ||
throw Error(`Source folder '${source}' not found.`); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Finds all defined icons in the bundle. | ||
* @returns {Promise<BundleIcon>} - A map of icon names to their respective blobs. | ||
*/ | ||
public async findDefinedIcons(): Promise<BundleIcons> { | ||
if (this.zip === undefined) { | ||
throw Error("Zip file not loaded."); | ||
} | ||
|
||
if (this.config === undefined) { | ||
throw Error("Configuration file not loaded."); | ||
} | ||
|
||
const result: BundleIcons = {}; | ||
const icons = this.config.getIcons(); | ||
|
||
for (const [key, value] of Object.entries(icons)) { | ||
const file = this.zip.file(value); | ||
|
||
if (file === null) continue; | ||
|
||
const blob = await file.async("blob"); | ||
result[key as keyof BundleIcons] = blob; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Fetches all files within the defined source directory. | ||
* @returns {Promise<Array<File>>} - An array of files within the source directory. | ||
*/ | ||
public async getSourceFiles(): Promise<Array<File>> { | ||
if (this.zip === undefined) { | ||
throw Error("Zip file not loaded."); | ||
} | ||
|
||
if (this.config === undefined) { | ||
throw Error("Configuration file not loaded."); | ||
} | ||
|
||
const source = this.config.build.source; | ||
|
||
const files = await Promise.all( | ||
this.zip | ||
.file(new RegExp(`^${source}/.+`)) | ||
.map(async (file: JSZipObject) => { | ||
const blob = await file.async("blob"); | ||
const length = source.length + 1; | ||
|
||
return new File([blob], file.name.slice(length)); | ||
}) | ||
); | ||
|
||
return files; | ||
} | ||
|
||
public getMetadata(): ConfigMetadata { | ||
if (this.config === undefined) { | ||
throw Error("Configuration file not loaded."); | ||
} | ||
|
||
return this.config.metadata; | ||
} | ||
|
||
public getTargets(): Array<string> { | ||
if (this.config === undefined) { | ||
throw Error("Configuration file not loaded."); | ||
} | ||
|
||
return this.config.build.targets; | ||
} | ||
|
||
public isPackaged(): boolean { | ||
if (this.config === undefined) { | ||
throw Error("Configuration file not loaded."); | ||
} | ||
|
||
return this.config.isPackaged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import toml from "toml"; | ||
|
||
export type ConfigIcons = { | ||
ctr?: string; | ||
cafe?: string; | ||
hac?: string; | ||
}; | ||
|
||
export type ConfigMetadata = { | ||
title: string; | ||
author: string; | ||
description: string; | ||
version: string; | ||
icons: ConfigIcons; | ||
}; | ||
|
||
export type ConfigBuild = { | ||
targets: Array<string>; | ||
source: string; | ||
packaged?: boolean; | ||
}; | ||
|
||
export default class Config { | ||
metadata!: ConfigMetadata; | ||
build!: ConfigBuild; | ||
|
||
public getIcons(): ConfigIcons { | ||
return this.metadata.icons; | ||
} | ||
|
||
public getTargets(): Array<string> { | ||
return this.build.targets; | ||
} | ||
|
||
public isPackaged(): boolean { | ||
return this.build.packaged ?? false; | ||
} | ||
} | ||
|
||
export function parseConfig(content: string): Config { | ||
const configData = toml.parse(content); | ||
const config = new Config(); | ||
|
||
Object.assign(config, configData); | ||
return config; | ||
} |
Oops, something went wrong.