import { ChunkDB } from '../db/chunks' ; import { Chunk } from 'faces/chunk' ; import Router from 'koa-router' ; let chunkDB ; let oldDbPath ; export async function postChunkRoute ( ctx ) { try { if ( oldDbPath !== ctx . dbPath || ! chunkDB ) { chunkDB = new ChunkDB ( ctx . connection ) ; oldDbPath = ctx . dbPath ; } const chunk = ctx . request . body as unknown as Chunk ; await chunkDB . create ( chunk ) ; ctx . body = { } ; } catch ( error ) { console . error ( { error } ) ; } } export async function getChunkOffsetRoute ( ctx ) { try { if ( ! chunkDB ) { chunkDB = new ChunkDB ( ctx . connection ) ; } const offset = + ctx . params . offset ; ctx . body = await chunkDB . getByOffset ( offset ) ; } catch ( error ) { console . error ( { error } ) ; } }