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 { serve } from "https://deno.land/std/http/mod.ts"; | |
| async function reqHandler(req: Request) { | |
| if ( | |
| !req.headers.has("Authorization") || | |
| req.headers.get("Authorization")?.split(" ")[1] !== | |
| Deno.env.get("AUTH_TOKEN") | |
| ) { | |
| return new Response(null, { status: 401 }); | |
| } | 
  
    
      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 { | |
| decode as hd, | |
| encode as he, | |
| } from "https://deno.land/std/encoding/hex.ts"; | |
| const te = (s: string) => new TextEncoder().encode(s), | |
| td = (d: Uint8Array) => new TextDecoder().decode(d); | |
| const rawKey = new Uint8Array([ | |
| 238, | |
| 17, | 
  
    
      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 { readableStreamFromReader as toStream } from "https://deno.land/std/streams/mod.ts"; | |
| import { serve } from "https://deno.land/std/http/mod.ts"; | |
| const BASE_PATH = "./testdata"; | |
| const reqHandler = async (req: Request) => { | |
| const p = new URL(req.url).pathname; | |
| const filePath = BASE_PATH + p; | |
| let len = 0; | |
| try { | 
  
    
      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 { serve } from "https://deno.land/std/http/mod.ts"; | |
| const BASE_PATH = "file:///var/tmp/testdata"; | |
| const reqHandler = async (req: Request) => { | |
| const p = new URL(req.url).pathname; | |
| const filePath = BASE_PATH + p; | |
| try { | |
| const res = await fetch(filePath); | |
| return new Response(res.body); | 
  
    
      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 * as Eta from "https://deno.land/x/eta/mod.ts"; | |
| import { serve } from "https://deno.land/std/http/mod.ts"; | |
| Eta.configure({ views: "./" }); | |
| const getName = (u: URL) => u.searchParams.get("name") || "James Bond 007"; | |
| const reqHandler = async (req: Request) => { | |
| try { | |
| const u = new URL(req.url); | 
  
    
      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 { API_KEYS_PATH } from "./consts.ts"; | |
| let apiKeys: Array<string>=[]; | |
| try { | |
| apiKeys=JSON.parse(Deno.readTextFileSync(API_KEYS_PATH)); | |
| } catch (e) {} | |
| export function authorize(headers: Headers) { | |
| const authorized=true, notAuthorized=false; | |
| if (!apiKeys.length) | 
  
    
      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 { API_KEYS_PATH } from "./consts.ts"; | |
| let apiKeys: Array<string> = []; | |
| try { | |
| apiKeys = JSON.parse(Deno.readTextFileSync(API_KEYS_PATH)); | |
| } catch (_e) { | |
| console.info("No API keys found, authentication is disabled"); | |
| } | |
| export function authorize(headers: Headers) { | 
  
    
      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 { authorize } from "../authService.ts"; | |
| import { assert, assertExists } from "https://deno.land/std/testing/asserts.ts"; | |
| Deno.test("No headers", async () => { | |
| const headers = new Headers(); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === false); | |
| }); | 
  
    
      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 { getContent } from "../../fileService.ts"; | |
| import { | |
| assert, | |
| assertExists, | |
| assertThrowsAsync, | |
| } from "https://deno.land/std/testing/asserts.ts"; | |
| async function readStream(r: ReadableStream) { | |
| const rd = r.getReader(); | |
| assertExists(rd); | 
  
    
      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 { handleRequest } from "../../controller.ts"; | |
| import { assert, assertExists } from "https://deno.land/std/testing/asserts.ts"; | |
| const baseUrl = "http://localhost:8000", | |
| token = "cba633d4-59f3-42a5-af00-b7430c3a65d8"; | |
| Deno.test("No Authorization header", async () => { | |
| const req = new Request(baseUrl + "/"); | |
| const resp = await handleRequest(req); | |
| assertExists(resp); |