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 { 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(
ctx: Context,
data: Record<string, FormDataValue>,
field_prefix: string,
form_id: string
): Promise<Record<string, string | boolean>> {
const original = await super.getInputAttributes(
ctx,
data,
field_prefix,
form_id
);
const { parsed } = await this.field.getValue(ctx, 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, 10:43 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
983657
Default Alt Text
file.ts (1 KB)

Event Timeline