51 lines
1.4 KiB
Plaintext
51 lines
1.4 KiB
Plaintext
module Main where
|
|
|
|
import Prelude
|
|
|
|
import Effect (Effect)
|
|
import Effect.Aff (Aff, launchAff)
|
|
import Effect.Class (liftEffect)
|
|
import Effect.Console (log)
|
|
import Fetch (fetch)
|
|
import Data.Binary.Base64 (decode)
|
|
import Data.Either (Either, hush, note)
|
|
import Data.ArrayBuffer.Types (Uint8Array)
|
|
import Data.Maybe (Maybe(..))
|
|
import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
|
|
import Data.String (drop, indexOf', indexOf, splitAt)
|
|
import Data.String.Pattern (Pattern(..))
|
|
|
|
data AviaryError
|
|
= MalformedKey
|
|
| MalformedUrl
|
|
|
|
instance showAviaryError :: Show AviaryError where
|
|
show MalformedKey = "Malformed key!!"
|
|
show MalformedUrl = "Malformed url!!"
|
|
|
|
type UrlInfo =
|
|
{ server :: String
|
|
, fileId :: String
|
|
, key :: String
|
|
}
|
|
|
|
parseUrl :: String -> Either AviaryError UrlInfo
|
|
parseUrl url = note MalformedUrl do
|
|
slashIndex <- indexOf' (Pattern "/") 8 url
|
|
let { after, before: server } = splitAt (1 + slashIndex) url
|
|
poundIndex <- indexOf (Pattern "#") after
|
|
let { after: key, before: fileId } = splitAt poundIndex after
|
|
Just { server, fileId, key: drop 1 key }
|
|
|
|
decodeKey :: String -> Either AviaryError Uint8Array
|
|
decodeKey key = note MalformedKey $ hush $ decode key
|
|
|
|
main_aff :: Aff Unit
|
|
main_aff = do
|
|
{ status, text } <- fetch "https://envs.sh/Q_V.txt" {}
|
|
responseText <- text
|
|
liftEffect $ log responseText
|
|
|
|
main :: Effect Unit
|
|
main = launchAff main_aff $> unit
|