Reduce lint errors
This commit is contained in:
@@ -79,7 +79,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
contentType: contentType,
|
||||
},
|
||||
};
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// console.error("Error while reading file", name, e);
|
||||
throw Error(`Could not read file ${name}`);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
lastModified: s.mtime!.getTime(),
|
||||
perm: "rw",
|
||||
};
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// console.error("Error while getting page meta", pageName, e);
|
||||
throw Error(`Could not get meta for ${name}`);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
continue;
|
||||
}
|
||||
const fullPath = path.join(dir, file.name);
|
||||
let s = await Deno.stat(fullPath);
|
||||
const s = await Deno.stat(fullPath);
|
||||
if (file.isDirectory) {
|
||||
await walkPath(fullPath);
|
||||
} else {
|
||||
@@ -180,7 +180,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
// Plugs
|
||||
invokeFunction(
|
||||
plug: Plug<any>,
|
||||
env: string,
|
||||
_env: string,
|
||||
name: string,
|
||||
args: any[],
|
||||
): Promise<any> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AttachmentMeta, FileMeta, PageMeta } from "../types.ts";
|
||||
import { FileMeta } from "../types.ts";
|
||||
import { Plug } from "../../plugos/plug.ts";
|
||||
import { FileData, FileEncoding, SpacePrimitives } from "./space_primitives.ts";
|
||||
|
||||
@@ -21,7 +21,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
options.headers = options.headers || {};
|
||||
options.headers["Authorization"] = `Bearer ${this.token}`;
|
||||
}
|
||||
let result = await fetch(url, options);
|
||||
const result = await fetch(url, options);
|
||||
if (result.status === 401) {
|
||||
throw Error("Unauthorized");
|
||||
}
|
||||
@@ -29,20 +29,18 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
}
|
||||
|
||||
public async fetchFileList(): Promise<FileMeta[]> {
|
||||
let req = await this.authenticatedFetch(this.fsUrl, {
|
||||
const req = await this.authenticatedFetch(this.fsUrl, {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
let result: FileMeta[] = await req.json();
|
||||
|
||||
return result;
|
||||
return req.json();
|
||||
}
|
||||
|
||||
async readFile(
|
||||
name: string,
|
||||
encoding: FileEncoding,
|
||||
): Promise<{ data: FileData; meta: FileMeta }> {
|
||||
let res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
const res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
method: "GET",
|
||||
});
|
||||
if (res.status === 404) {
|
||||
@@ -52,13 +50,13 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
switch (encoding) {
|
||||
case "arraybuffer":
|
||||
{
|
||||
let abBlob = await res.blob();
|
||||
const abBlob = await res.blob();
|
||||
data = await abBlob.arrayBuffer();
|
||||
}
|
||||
break;
|
||||
case "dataurl":
|
||||
{
|
||||
let dUBlob = await res.blob();
|
||||
const dUBlob = await res.blob();
|
||||
data = arrayBufferToDataUrl(await dUBlob.arrayBuffer());
|
||||
}
|
||||
break;
|
||||
@@ -76,7 +74,6 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
name: string,
|
||||
encoding: FileEncoding,
|
||||
data: FileData,
|
||||
selfUpdate?: boolean,
|
||||
): Promise<FileMeta> {
|
||||
let body: any = null;
|
||||
|
||||
@@ -89,7 +86,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
data = dataUrlToArrayBuffer(data as string);
|
||||
break;
|
||||
}
|
||||
let res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
const res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-type": "application/octet-stream",
|
||||
@@ -101,7 +98,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
}
|
||||
|
||||
async deleteFile(name: string): Promise<void> {
|
||||
let req = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
const req = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
if (req.status !== 200) {
|
||||
@@ -110,7 +107,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
}
|
||||
|
||||
async getFileMeta(name: string): Promise<FileMeta> {
|
||||
let res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
const res = await this.authenticatedFetch(`${this.fsUrl}/${name}`, {
|
||||
method: "OPTIONS",
|
||||
});
|
||||
if (res.status === 404) {
|
||||
@@ -132,7 +129,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
// Plugs
|
||||
|
||||
async proxySyscall(plug: Plug<any>, name: string, args: any[]): Promise<any> {
|
||||
let req = await this.authenticatedFetch(
|
||||
const req = await this.authenticatedFetch(
|
||||
`${this.plugUrl}/${plug.name}/syscall/${name}`,
|
||||
{
|
||||
method: "POST",
|
||||
@@ -143,7 +140,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
},
|
||||
);
|
||||
if (req.status !== 200) {
|
||||
let error = await req.text();
|
||||
const error = await req.text();
|
||||
throw Error(error);
|
||||
}
|
||||
if (req.headers.get("Content-length") === "0") {
|
||||
@@ -163,7 +160,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
return plug.invoke(name, args);
|
||||
}
|
||||
// Or dispatch to server
|
||||
let req = await this.authenticatedFetch(
|
||||
const req = await this.authenticatedFetch(
|
||||
`${this.plugUrl}/${plug.name}/function/${name}`,
|
||||
{
|
||||
method: "POST",
|
||||
@@ -174,7 +171,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
},
|
||||
);
|
||||
if (req.status !== 200) {
|
||||
let error = await req.text();
|
||||
const error = await req.text();
|
||||
throw Error(error);
|
||||
}
|
||||
if (req.headers.get("Content-length") === "0") {
|
||||
@@ -189,21 +186,21 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
}
|
||||
|
||||
function dataUrlToArrayBuffer(dataUrl: string): ArrayBuffer {
|
||||
var binary_string = window.atob(dataUrl.split(",")[1]);
|
||||
var len = binary_string.length;
|
||||
var bytes = new Uint8Array(len);
|
||||
for (var i = 0; i < len; i++) {
|
||||
const binary_string = atob(dataUrl.split(",")[1]);
|
||||
const len = binary_string.length;
|
||||
const bytes = new Uint8Array(len);
|
||||
for (let i = 0; i < len; i++) {
|
||||
bytes[i] = binary_string.charCodeAt(i);
|
||||
}
|
||||
return bytes.buffer;
|
||||
}
|
||||
|
||||
function arrayBufferToDataUrl(buffer: ArrayBuffer): string {
|
||||
var binary = "";
|
||||
var bytes = new Uint8Array(buffer);
|
||||
var len = bytes.byteLength;
|
||||
for (var i = 0; i < len; i++) {
|
||||
let binary = "";
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const len = bytes.byteLength;
|
||||
for (let i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return `data:application/octet-stream,${window.btoa(binary)}`;
|
||||
return `data:application/octet-stream,${btoa(binary)}`;
|
||||
}
|
||||
|
||||
+10
-10
@@ -25,9 +25,9 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
}
|
||||
|
||||
public async updatePageList() {
|
||||
let newPageList = await this.fetchPageList();
|
||||
const newPageList = await this.fetchPageList();
|
||||
// console.log("Updating page list", newPageList);
|
||||
let deletedPages = new Set<string>(this.pageMetaCache.keys());
|
||||
const deletedPages = new Set<string>(this.pageMetaCache.keys());
|
||||
newPageList.forEach((meta) => {
|
||||
const pageName = meta.name;
|
||||
const oldPageMeta = this.pageMetaCache.get(pageName);
|
||||
@@ -84,7 +84,7 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
this.updatePageList().catch(console.error);
|
||||
}
|
||||
|
||||
async deletePage(name: string, deleteDate?: number): Promise<void> {
|
||||
async deletePage(name: string): Promise<void> {
|
||||
await this.getPageMeta(name); // Check if page exists, if not throws Error
|
||||
await this.space.deleteFile(`${name}.md`);
|
||||
|
||||
@@ -94,8 +94,8 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
}
|
||||
|
||||
async getPageMeta(name: string): Promise<PageMeta> {
|
||||
let oldMeta = this.pageMetaCache.get(name);
|
||||
let newMeta = fileMetaToPageMeta(
|
||||
const oldMeta = this.pageMetaCache.get(name);
|
||||
const newMeta = fileMetaToPageMeta(
|
||||
await this.space.getFileMeta(`${name}.md`),
|
||||
);
|
||||
if (oldMeta) {
|
||||
@@ -121,7 +121,7 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
}
|
||||
|
||||
async listPlugs(): Promise<string[]> {
|
||||
let allFiles = await this.space.fetchFileList();
|
||||
const allFiles = await this.space.fetchFileList();
|
||||
return allFiles
|
||||
.filter((fileMeta) => fileMeta.name.endsWith(".plug.json"))
|
||||
.map((fileMeta) => fileMeta.name);
|
||||
@@ -132,16 +132,16 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
}
|
||||
|
||||
async readPage(name: string): Promise<{ text: string; meta: PageMeta }> {
|
||||
let pageData = await this.space.readFile(`${name}.md`, "string");
|
||||
let previousMeta = this.pageMetaCache.get(name);
|
||||
let newMeta = fileMetaToPageMeta(pageData.meta);
|
||||
const pageData = await this.space.readFile(`${name}.md`, "string");
|
||||
const previousMeta = this.pageMetaCache.get(name);
|
||||
const newMeta = fileMetaToPageMeta(pageData.meta);
|
||||
if (previousMeta) {
|
||||
if (previousMeta.lastModified !== newMeta.lastModified) {
|
||||
// Page changed since last cached metadata, trigger event
|
||||
this.emit("pageChanged", newMeta);
|
||||
}
|
||||
}
|
||||
let meta = this.metaCacher(name, newMeta);
|
||||
const meta = this.metaCacher(name, newMeta);
|
||||
return {
|
||||
text: pageData.data as string,
|
||||
meta: meta,
|
||||
|
||||
Reference in New Issue
Block a user