Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit b5aeaa4

Browse files
committed
infra: fixup presentation name
1 parent c9d1402 commit b5aeaa4

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

infra/handler/app/Test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ testPresDeploys = withQueueName $ withEnv $ \env -> withSQS env $ withS3 env $ d
168168
let someSlide = Slide (Just "foo") "bar" HMS.empty
169169

170170
let somePres = PresentationInfo
171-
{ presentationName = Deckname "some-pres"
171+
{ presentationName = PresentationName "some-pres"
172172
, presentationSlides = [someSlide]
173173
, presentationOwner = someUserId
174174
, presentationAttributes = HMS.empty

infra/handler/src/DeckGo/Handler.hs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ instance ToSchema UserInfo where
233233
instance ToParamSchema (Item UserId UserInfo) where
234234
toParamSchema _ = mempty
235235

236-
newtype Deckname = Deckname { unDeckname :: T.Text }
236+
newtype PresentationName = PresentationName { unPresentatinName :: T.Text }
237237
deriving stock (Show, Eq)
238238
deriving newtype (Aeson.FromJSON, Aeson.ToJSON)
239239

240-
newtype Deckbackground = Deckbackground { unDeckbackground :: T.Text }
240+
newtype PresentationBackground = PresentationBackground { unPresentationBackground :: T.Text }
241241
deriving stock (Show, Eq)
242242
deriving newtype (Aeson.FromJSON, Aeson.ToJSON)
243243

@@ -306,9 +306,9 @@ newtype PresentationId = PresentationId { unPresentationId :: T.Text }
306306
instance ToParamSchema PresentationId
307307

308308
data PresentationInfo = PresentationInfo
309-
{ presentationName :: Deckname
309+
{ presentationName :: PresentationName
310310
, presentationOwner :: UserId
311-
, presentationBackground :: Maybe Deckbackground
311+
, presentationBackground :: Maybe PresentationBackground
312312
, presentationAttributes :: HMS.HashMap T.Text T.Text
313313
, presentationSlides :: [Slide]
314314
} deriving (Show, Eq)
@@ -420,7 +420,7 @@ presentationsPost env conn _userId pinfo = do
420420
let presName = presentationPrefix uname (presentationName pinfo)
421421

422422
-- something fishy going on here
423-
let presName' = sanitizeDeckname (presentationName pinfo)
423+
let presName' = sanitizePresentationName (presentationName pinfo)
424424

425425
liftIO $ putStrLn $ unwords
426426
[ "Presentation info:"
@@ -484,7 +484,7 @@ presentationsPut env conn _uid pid pinfo = do
484484
liftIO $ putStrLn $ "Got presentation: " <> show (presName, presUrl)
485485

486486
-- XXX: huge hack because we know we stored the "correct" presentation name
487-
let pinfo' = pinfo { presentationName = Deckname presName }
487+
let pinfo' = pinfo { presentationName = PresentationName presName }
488488

489489
liftIO $ putStrLn $ "Updated presentation info: " <> show pinfo
490490
liftIO $ deployPresentation env uname pinfo'
@@ -1168,12 +1168,12 @@ tshow :: Show a => a -> T.Text
11681168
tshow = T.pack . show
11691169

11701170
-- TODO: what happens when the deckname is "-" ?
1171-
presentationPrefix :: Username -> Deckname -> T.Text
1172-
presentationPrefix uname dname =
1173-
unUsername uname <> "/" <> sanitizeDeckname dname <> "/"
1171+
presentationPrefix :: Username -> PresentationName -> T.Text
1172+
presentationPrefix uname pname =
1173+
unUsername uname <> "/" <> sanitizePresentationName pname <> "/"
11741174

1175-
sanitizeDeckname :: Deckname -> T.Text
1176-
sanitizeDeckname = T.toLower . strip . dropBadChars . unDeckname
1175+
sanitizePresentationName :: PresentationName -> T.Text
1176+
sanitizePresentationName = T.toLower . strip . dropBadChars . unPresentatinName
11771177
where
11781178
strip :: T.Text -> T.Text
11791179
strip = T.dropAround ( == '-' )
@@ -1214,10 +1214,10 @@ listPresentationObjects
12141214
:: AWS.Env
12151215
-> S3.BucketName
12161216
-> Username
1217-
-> Deckname
1217+
-> PresentationName
12181218
-> IO [S3.Object]
1219-
listPresentationObjects env bucket uname dname =
1220-
listObjects env bucket (Just $ presentationPrefix uname dname)
1219+
listPresentationObjects env bucket uname pname =
1220+
listObjects env bucket (Just $ presentationPrefix uname pname)
12211221

12221222
withPresentationFiles
12231223
:: Username
@@ -1234,27 +1234,27 @@ withPresentationFiles uname presentationInfo act = do
12341234
files <- listDirectoryRecursive dir
12351235
files' <- forM files $ \(fp, components) -> do
12361236
etag <- fileETag fp
1237-
let okey = mkObjectKey uname dname components
1237+
let okey = mkObjectKey uname pname components
12381238
pure (fp, okey, etag)
12391239
act files'
12401240
where
1241-
dname = presentationName presentationInfo
1241+
pname = presentationName presentationInfo
12421242
processIndex :: T.Text -> T.Text
12431243
processIndex =
12441244
TagSoup.renderTags . processTags presentationInfo . TagSoup.parseTags .
12451245
interpol
12461246
interpol =
1247-
T.replace "{{DECKDECKGO_TITLE}}" (unDeckname dname) .
1248-
T.replace "{{DECKDECKGO_TITLE_SHORT}}" (T.take 12 $ unDeckname dname) .
1247+
T.replace "{{DECKDECKGO_TITLE}}" (unPresentatinName pname) .
1248+
T.replace "{{DECKDECKGO_TITLE_SHORT}}" (T.take 12 $ unPresentatinName pname) .
12491249
T.replace "{{DECKDECKGO_AUTHOR}}" (unUsername uname) .
12501250
T.replace "{{DECKDECKGO_USERNAME}}" (unUsername uname) .
12511251
T.replace "{{DECKDECKGO_USER_ID}}"
12521252
(unFirebaseId . unUserId $ presentationOwner presentationInfo) .
1253-
T.replace "{{DECKDECKGO_DECKNAME}}" (sanitizeDeckname dname) .
1253+
T.replace "{{DECKDECKGO_DECKNAME}}" (sanitizePresentationName pname) .
12541254
-- TODO: description
12551255
T.replace "{{DECKDECKGO_DESCRIPTION}}" "(no description given)" .
12561256
T.replace "{{DECKDECKGO_BASE_HREF}}"
1257-
("/" <> presentationPrefix uname dname)
1257+
("/" <> presentationPrefix uname pname)
12581258

12591259
mapFile :: (T.Text -> T.Text) -> FilePath -> IO ()
12601260
mapFile f fp = do
@@ -1268,11 +1268,12 @@ processTags presentationInfo = concatMap $ \case
12681268
| str == "deckgo-deck" -> do
12691269
[ TagSoup.TagOpen str (HMS.toList (presentationAttributes presentationInfo <> attrs)) ] <>
12701270
(concatMap slideTags (presentationSlides presentationInfo)) <>
1271-
(maybe [] deckBackgroundTags (presentationBackground presentationInfo))
1271+
(maybe [] presentationBackgroundTags
1272+
(presentationBackground presentationInfo))
12721273
t -> [t]
12731274

1274-
deckBackgroundTags :: Deckbackground -> [Tag]
1275-
deckBackgroundTags (unDeckbackground -> bg) =
1275+
presentationBackgroundTags :: PresentationBackground -> [Tag]
1276+
presentationBackgroundTags (unPresentationBackground -> bg) =
12761277
[ TagSoup.TagOpen "div" (HMS.toList $ HMS.singleton "slot" "background")
12771278
] <> TagSoup.parseTags bg <>
12781279
[ TagSoup.TagClose "div"
@@ -1320,9 +1321,9 @@ deployPresentation :: AWS.Env -> Username -> PresentationInfo -> IO ()
13201321
deployPresentation env uname presentationInfo = do
13211322
bucketName <- getEnv "BUCKET_NAME"
13221323
let bucket = S3.BucketName (T.pack bucketName)
1323-
let dname = presentationName presentationInfo
1324+
let pname = presentationName presentationInfo
13241325
putStrLn "Listing current objects"
1325-
currentObjs <- listPresentationObjects env bucket uname dname
1326+
currentObjs <- listPresentationObjects env bucket uname pname
13261327
putStrLn "Listing presentations files"
13271328

13281329
withPresentationFiles uname presentationInfo $ \files -> do
@@ -1351,7 +1352,7 @@ deployPresentation env uname presentationInfo = do
13511352
liftIO $ print queueUrl
13521353

13531354
res <- runAWS env $ AWS.send $ SQS.sendMessage queueUrl $
1354-
T.decodeUtf8 $ BL.toStrict $ Aeson.encode (presentationPrefix uname dname)
1355+
T.decodeUtf8 $ BL.toStrict $ Aeson.encode (presentationPrefix uname pname)
13551356

13561357
case res of
13571358
Right r -> do
@@ -1399,9 +1400,9 @@ fixupS3ETag (S3.ETag etag) =
13991400
T.dropWhile (== '"') $
14001401
T.decodeUtf8 etag
14011402

1402-
mkObjectKey :: Username -> Deckname -> [T.Text] -> S3.ObjectKey
1403-
mkObjectKey uname dname components = S3.ObjectKey $
1404-
presentationPrefix uname dname <> T.intercalate "/" components
1403+
mkObjectKey :: Username -> PresentationName -> [T.Text] -> S3.ObjectKey
1404+
mkObjectKey uname pname components = S3.ObjectKey $
1405+
presentationPrefix uname pname <> T.intercalate "/" components
14051406

14061407
fileETag :: FilePath -> IO S3.ETag
14071408
fileETag fp =

0 commit comments

Comments
 (0)