Page MenuHomeSealhub

file.ts
No OneTemporary

import { Context } from "koa";
import { FlatTemplatable, tempstream } from "tempstream";
import { FileContainer } from "../fields/file";
import { FormDataValue } from "../form";
import { FormControlContext } from "./form-control";
import { SimpleInput } from "./simple-input";
export class File extends SimpleInput<FileContainer> {
getType() {
return "file";
}
async renderFilePreview(
_ctx: Context,
file_data: { id?: string; filename?: string } | null
): Promise<FlatTemplatable> {
return file_data?.filename || "";
}
async preInput(ctx: Context, data: Record<string, FormDataValue>) {
const { parsed } = await this.field.getValue(ctx, data);
return tempstream/* HTML */ `${this.renderFilePreview(ctx, parsed.old)}
<input
type="hidden"
name="${this.field.name}[old][id]"
value="${parsed.old?.id || ""}"
/>
<input
type="hidden"
name="${this.field.name}[old][filename]"
value="${parsed.old?.filename || ""}"
/>`;
}
async getInputAttributes(
fctx: FormControlContext
): Promise<Record<string, string | boolean>> {
const original = await super.getInputAttributes(fctx);
const { parsed } = await this.field.getValue(fctx.ctx, fctx.data);
return {
...original,
name: this.field.name + "[new]",
required: original.required && !parsed.old,
value: false,
};
}
}

File Metadata

Mime Type
text/x-java
Expires
Sat, Oct 11, 05:56 (22 m, 38 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
971966
Default Alt Text
file.ts (1 KB)

Event Timeline