-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
171 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"$/": "./", | ||
"$fresh/": "https://deno.land/x/[email protected]/", | ||
"$std/": "https://deno.land/[email protected]/", | ||
"@open-schemas/zod": "jsr:@open-schemas/zod@^0.8.4", | ||
"@open-schemas/zod": "jsr:@open-schemas/zod@^0.9.2", | ||
"@std/assert": "jsr:@std/assert@^0.221.0", | ||
"@std/log": "jsr:@std/log@^0.221.0", | ||
"@std/testing": "jsr:@std/testing@^0.221.0", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,31 @@ | ||
import { Repository } from "$/repositories/_repository.ts"; | ||
import type { FileObjectType } from "$/schemas/file.ts"; | ||
import { FileObject } from "@open-schemas/zod/openai"; | ||
import { Repository } from "$/repositories/base.ts"; | ||
import { FILE_KEY, FILE_OBJECT, FILE_PREFIX, ORGANIZATION } from "$/consts/api.ts"; | ||
|
||
export class FileRepository extends Repository { | ||
static idPrefix = "file"; | ||
static object = "file"; | ||
static parent = "organization"; | ||
static self = "file"; | ||
export class FileRepository extends Repository<FileObject> { | ||
private static instance: FileRepository; | ||
|
||
static async sumFileSize(org: string) { | ||
const files = await this.findAll<FileObjectType>(org); | ||
return files.reduce((pre, cur) => pre + cur.bytes, 0); | ||
private constructor() { | ||
super(FILE_PREFIX, FILE_OBJECT, ORGANIZATION, FILE_KEY); | ||
} | ||
|
||
// private static genFileSizeKey(org: string) { | ||
// return [this.parent, org, "file_size"]; | ||
// } | ||
|
||
// static async createWithBytes( | ||
// fields: Partial<FileObjectType>, | ||
// organization: string, | ||
// ) { | ||
// const operation = kv.atomic(); | ||
// const { value } = await this.create<FileObjectType>( | ||
// fields, | ||
// organization, | ||
// operation, | ||
// ); | ||
// operation.sum( | ||
// [this.parent, organization, "file_size"], | ||
// BigInt(value.bytes), | ||
// ); | ||
|
||
// const { ok } = await operation.commit(); | ||
// if (!ok) throw new DbCommitError(); | ||
// return { value }; | ||
// } | ||
public static getInstance(): FileRepository { | ||
if (!FileRepository.instance) { | ||
FileRepository.instance = new FileRepository(); | ||
} | ||
return FileRepository.instance; | ||
} | ||
|
||
// static async destoryWithBytes(id: string, org: string, bytes: number) { | ||
// const operation = kv.atomic(); | ||
// this.destory(id, org, operation); | ||
async sumFileSize(org: string) { | ||
const files = await this.findAll(org); | ||
return files.reduce((pre, cur) => pre + cur.bytes, 0); | ||
} | ||
|
||
// operation.sum(this.genFileSizeKey(org), -BigInt(bytes)); | ||
// } | ||
async findByPurpose(organization: string, purpose?: string) { | ||
const files = await this.findAll(organization); | ||
if (purpose) { | ||
return files.filter((f) => f.purpose === purpose); | ||
} | ||
return files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FreshContext, Handlers } from "$fresh/server.ts"; | ||
import { FileObject } from "@open-schemas/zod/openai"; | ||
import { getFile } from "$/routes/v1/files/[file_id].ts"; | ||
import { getFileDir } from "$/utils/file.ts"; | ||
|
||
export const handler: Handlers<FileObject | null> = { | ||
async GET(_req, ctx: FreshContext) { | ||
const fileObject = await getFile(ctx); | ||
const organization = ctx.state.organization as string; | ||
const dirPath = `${getFileDir()}/${organization}`; | ||
const file = await Deno.open(`${dirPath}/${fileObject.id}`, { read: true }); | ||
return new Response(file.readable); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.