Fixes #90: Re-enables full text search
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { assertEquals } from "../../test_deps.ts";
|
||||
import { base64Decode } from "./base64.ts";
|
||||
import {
|
||||
base64Decode,
|
||||
base64DecodeDataUrl,
|
||||
base64EncodedDataUrl,
|
||||
} from "./base64.ts";
|
||||
import { base64Encode } from "./base64.ts";
|
||||
|
||||
Deno.test("Base 64 encoding", () => {
|
||||
@@ -9,4 +13,9 @@ Deno.test("Base 64 encoding", () => {
|
||||
buf[2] = 3;
|
||||
|
||||
assertEquals(buf, base64Decode(base64Encode(buf)));
|
||||
|
||||
assertEquals(
|
||||
buf,
|
||||
base64DecodeDataUrl(base64EncodedDataUrl("application/octet-stream", buf)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -16,3 +16,15 @@ export function base64Encode(buffer: Uint8Array): string {
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
export function base64EncodedDataUrl(
|
||||
mimeType: string,
|
||||
buffer: Uint8Array,
|
||||
): string {
|
||||
return `data:${mimeType};base64,${base64Encode(buffer)}`;
|
||||
}
|
||||
|
||||
export function base64DecodeDataUrl(dataUrl: string): Uint8Array {
|
||||
const b64Encoded = dataUrl.split(",", 2)[1];
|
||||
return base64Decode(b64Encoded);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { base64Decode, base64Encode } from "./base64.ts";
|
||||
import { base64Decode, base64EncodedDataUrl } from "./base64.ts";
|
||||
import { mime } from "../deps.ts";
|
||||
|
||||
type DataUrl = string;
|
||||
@@ -57,9 +57,8 @@ export class AssetBundle {
|
||||
}
|
||||
|
||||
writeFileSync(path: string, data: Uint8Array) {
|
||||
const encoded = base64Encode(data);
|
||||
const mimeType = mime.getType(path);
|
||||
this.bundle[path] = `data:${mimeType};base64,${encoded}`;
|
||||
const mimeType = mime.getType(path) || "application/octet-stream";
|
||||
this.bundle[path] = base64EncodedDataUrl(mimeType, data);
|
||||
}
|
||||
|
||||
writeTextFileSync(path: string, s: string) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SysCallMapping } from "../system.ts";
|
||||
import { mime, path } from "../deps.ts";
|
||||
import { base64Decode, base64Encode } from "../asset_bundle/base64.ts";
|
||||
import { base64DecodeDataUrl, base64Encode } from "../asset_bundle/base64.ts";
|
||||
import { FileMeta } from "../../common/types.ts";
|
||||
|
||||
export default function fileSystemSyscalls(root = "/"): SysCallMapping {
|
||||
@@ -51,7 +51,7 @@ export default function fileSystemSyscalls(root = "/"): SysCallMapping {
|
||||
if (encoding === "utf8") {
|
||||
await Deno.writeTextFile(p, text);
|
||||
} else {
|
||||
await Deno.writeFile(p, base64Decode(text.split(",")[1]));
|
||||
await Deno.writeFile(p, base64DecodeDataUrl(text));
|
||||
}
|
||||
const s = await Deno.stat(p);
|
||||
return {
|
||||
|
||||
@@ -2,27 +2,22 @@ import { SQLite } from "../../server/deps.ts";
|
||||
import { SysCallMapping } from "../system.ts";
|
||||
import { asyncExecute, asyncQuery } from "./store.deno.ts";
|
||||
|
||||
type Item = {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export function ensureFTSTable(
|
||||
db: SQLite,
|
||||
tableName: string,
|
||||
) {
|
||||
// const stmt = db.prepare(
|
||||
// `SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
||||
// );
|
||||
// const result = stmt.all(tableName);
|
||||
// if (result.length === 0) {
|
||||
// asyncExecute(
|
||||
// db,
|
||||
// `CREATE VIRTUAL TABLE ${tableName} USING fts5(key, value);`,
|
||||
// );
|
||||
const result = db.query(
|
||||
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
||||
[tableName],
|
||||
);
|
||||
if (result.length === 0) {
|
||||
asyncExecute(
|
||||
db,
|
||||
`CREATE VIRTUAL TABLE ${tableName} USING fts5(key, value);`,
|
||||
);
|
||||
|
||||
// console.log(`Created fts5 table ${tableName}`);
|
||||
// }
|
||||
console.log(`Created fts5 table ${tableName}`);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -44,6 +39,7 @@ export function fullTextSearchSyscalls(
|
||||
await asyncExecute(db, `DELETE FROM ${tableName} WHERE key = ?`, key);
|
||||
},
|
||||
"fulltext.search": async (_ctx, phrase: string, limit: number) => {
|
||||
console.log("Got search query", phrase);
|
||||
return (
|
||||
await asyncQuery<any>(
|
||||
db,
|
||||
|
||||
Reference in New Issue
Block a user