Fix minor inconsistencies

pull/503/head
Zef Hemel 2023-08-15 07:56:29 +02:00
parent cf97d04b1b
commit b47c07da74
3 changed files with 12 additions and 5 deletions

View File

@ -42,7 +42,7 @@ export function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
*/ */
export function readAttachment( export function readAttachment(
name: string, name: string,
): Promise<{ data: Uint8Array; meta: AttachmentMeta }> { ): Promise<Uint8Array> {
return syscall("space.readAttachment", name); return syscall("space.readAttachment", name);
} }

View File

@ -31,6 +31,9 @@ export async function publishCommand() {
} }
async function publish(pageName: string, uris: string[]) { async function publish(pageName: string, uris: string[]) {
if (!Array.isArray(uris)) {
uris = [uris];
}
for (const uri of uris) { for (const uri of uris) {
const publisher = uri.split(":")[0]; const publisher = uri.split(":")[0];
const results = await events.dispatchEvent( const results = await events.dispatchEvent(

View File

@ -17,9 +17,8 @@ export type SpaceEvents = {
const pageWatchInterval = 5000; const pageWatchInterval = 5000;
export class Space extends EventEmitter<SpaceEvents> { export class Space extends EventEmitter<SpaceEvents> {
pageMetaCache = new Map<string, PageMeta>();
imageHeightCache: Record<string, number> = {}; imageHeightCache: Record<string, number> = {};
pageMetaCache = new Map<string, PageMeta>();
debouncedCacheFlush = throttle(() => { debouncedCacheFlush = throttle(() => {
this.kvStore.set("imageHeightCache", this.imageHeightCache).catch( this.kvStore.set("imageHeightCache", this.imageHeightCache).catch(
@ -168,16 +167,21 @@ export class Space extends EventEmitter<SpaceEvents> {
} }
} }
// We're listing all pages that don't start with a _
isListedPageName(name: string): boolean {
return name.endsWith(".md") && !name.startsWith("_");
}
async fetchPageList(): Promise<PageMeta[]> { async fetchPageList(): Promise<PageMeta[]> {
return (await this.spacePrimitives.fetchFileList()) return (await this.spacePrimitives.fetchFileList())
.filter((fileMeta) => fileMeta.name.endsWith(".md")) .filter((fileMeta) => this.isListedPageName(fileMeta.name))
.map(fileMetaToPageMeta); .map(fileMetaToPageMeta);
} }
async fetchAttachmentList(): Promise<AttachmentMeta[]> { async fetchAttachmentList(): Promise<AttachmentMeta[]> {
return (await this.spacePrimitives.fetchFileList()).filter( return (await this.spacePrimitives.fetchFileList()).filter(
(fileMeta) => (fileMeta) =>
!fileMeta.name.endsWith(".md") && !this.isListedPageName(fileMeta.name) &&
!fileMeta.name.endsWith(".plug.js"), !fileMeta.name.endsWith(".plug.js"),
); );
} }