This file contains hidden or 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
    
  
  
    
  | import { Status } from "https://deno.land/std/http/http_status.ts" | |
| import {HTTP_METHOD_GET, HTTP_METHOD_POST, ROUTE_FILE_PATH} from "./constants.ts"; | |
| import {getFile, saveFile} from "./controller.ts"; | |
| import {sendResponseCode} from "./utils.ts"; | |
| export async function handleRequest(req: Request, resp: any) { | |
| const u=new URL(req.url); | |
| switch(u.pathname) { | |
| case ROUTE_FILE_PATH: { | |
| switch(req.method) { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {Status} from "https://deno.land/std/http/http_status.ts" | |
| import {HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, PARAM_FILE_NAME, PARAM_ID} from "./constants.ts"; | |
| import {sendResponseCode, sendResponseId, sendResponseFile, getQueryParam} from "./utils.ts"; | |
| import {fetch, store} from "./service.ts"; | |
| import {readerFromStreamReader} from "https://deno.land/std/io/mod.ts"; | |
| import {readAll} from "https://deno.land/std/io/mod.ts"; | |
| export async function getFile(req: Request, resp: any) { | |
| const u=new URL(req.url); | |
| const id=getQueryParam(u, PARAM_ID); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {DISK_FILE_PATH, CONTENT_TYPE_RAW, RECORD_DELIM} from "./constants.ts"; | |
| import {readAll} from "https://deno.land/std/io/mod.ts"; | |
| import {exists} from "https://deno.land/std/fs/mod.ts"; | |
| function getRecord(type:string, name:string="") { | |
| return type+RECORD_DELIM+name; | |
| } | |
| function parseRecord(rec:string) { | |
| const tkns=rec.split(RECORD_DELIM); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {readableStreamFromIterable} from "https://deno.land/std/io/mod.ts"; | |
| import {HEADER_CONTENT_TYPE, HEADER_CONTENT_DISPOSITION, HEADER_CONTENT_DISPOSITION_VAL} from "./constants.ts"; | |
| export function sendResponseCode(resp:any, code:number) { | |
| resp(new Response(undefined, {status: code})); | |
| } | |
| export function sendResponseId(resp:any, code:number, id:string) { | |
| const respBody=JSON.stringify({id}); | |
| resp(new Response(respBody, {status: code})); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | --abort-on-contradictory-flags (Disallow flags or implications overriding each other.) | |
| type: bool default: false | |
| --allow-overwriting-for-next-flag (temporary disable flag contradiction to allow overwriting just the next flag) | |
| type: bool default: false | |
| --use-strict (enforce strict mode) | |
| type: bool default: false | |
| --harmony (enable all completed harmony features) | |
| type: bool default: false | |
| --harmony-shipping (enable all shipped harmony features) | |
| type: bool default: true | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {PORT as port, SERVE_FILE_PATH} from "./constants.ts"; | |
| import {handleRequest} from "./router.ts"; | |
| if(!await checkSandbox(SERVE_FILE_PATH)) { | |
| console.error('Required read/net access is denied, exiting'); | |
| Deno.exit(1); | |
| } | |
| const listener = Deno.listen({port}); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import { Status } from "https://deno.land/std/http/http_status.ts"; | |
| import {HTTP_METHOD_GET} from "./constants.ts"; | |
| import {getFile} from "./controller.ts"; | |
| import {sendResponseCode} from "./utils.ts"; | |
| export async function handleRequest(req: Request, resp: any) { | |
| if(req.method !== HTTP_METHOD_GET) | |
| return sendResponseCode(resp, Status.MethodNotAllowed); | |
| const u=new URL(req.url); | |
| if(u.pathname === '/') | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {Status} from "https://deno.land/std/http/http_status.ts" | |
| import {getContentType} from "./utils.ts"; | |
| import {sendResponseCode, sendResponseFile} from "./utils.ts"; | |
| import {fetch} from "./service.ts"; | |
| export async function getFile(path: string, resp: any) { | |
| const f=await fetch(path); | |
| if(!f) | |
| return sendResponseCode(resp, Status.NotFound); | |
| const ct=getContentType(path); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {exists} from "https://deno.land/std/fs/mod.ts"; | |
| import {SERVE_FILE_PATH} from "./constants.ts"; | |
| export async function fetch(path:string) { | |
| const filePath=SERVE_FILE_PATH+path; | |
| if(!await exists(filePath)) | |
| return; | |
| const size=(await Deno.stat(filePath)).size; | |
| return {size, r: await Deno.open(filePath)}; | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import {getPort, getPath} from "./utils.ts"; | |
| export const PORT=getPort('SERVER_PORT', 5000); | |
| export const SERVE_FILE_PATH=getPath('SERVE_FILE_PATH', Deno.args[0] || './'); | |
| export const HTTP_METHOD_GET='GET'; | |
| export const HEADER_CONTENT_TYPE='content-type'; | |
| export const HEADER_CONTENT_LENGTH='content-length'; | |
| export const CONTENT_TYPE_RAW='application/octet-stream'; | |
| export const EXTENSION_TO_CONTENT_TYPE:Record<string,string>={ | |
| '.bin': 'application/octet-stream', |