~alcinnz/rhapsode

f04e3b5f1560cd033afebee626adf15c47ffd5c2 — Adrian Cochrane 4 years ago c0815fb
Don't delete downloads, was happening before use.
2 files changed, 12 insertions(+), 7 deletions(-)

M src/Input.hs
M src/Render.hs
M src/Input.hs => src/Input.hs +10 -6
@@ 57,18 57,22 @@ parseDocument _ ("application/xhtml+xml", Left text) | Right doc <- XML.parseTex
parseDocument _ ("application/xhtml+xml", Right bytes) | Right doc <- XML.parseLBS def bytes = return doc
  | otherwise = return $ docForText "Unreadable webpage!"
parseDocument session (mime, download) = do
    localURI <- withSystemTempFile "rhapsode-download" $ writeDownloadToFile download
    localURI <- writeDownloadToFile download
    result <- dispatchByMIME session mime localURI
    -- I'm not sure when I can delete this file.
    case result of
        Just text -> return $ docForText $ Txt.pack text
        Nothing -> parseDocument session ("application/xhtml+xml", download)

writeDownloadToFile (Left text) file handle = do
    hPutStr handle $ Txt.unpack text
    return $ URI "file:" Nothing file "" ""
writeDownloadToFile (Right bytes) file handle = do
writeDownloadToFile (Left text) = do
    path <- writeSystemTempFile "rhapsode-download" $ Txt.unpack text
    return $ URI "file:" (Just $ URIAuth "" "" "") path "" ""

writeDownloadToFile (Right bytes) = do
    temp <- getCanonicalTemporaryDirectory
    (path, handle) <- openBinaryTempFile temp "rhapsode-download"
    B.hPut handle bytes
    return $ URI "file:" Nothing file "" ""
    return $ URI "file:" (Just $ URIAuth "" "" "") path "" ""

docForText txt = XML.Document {
        XML.documentPrologue = XML.Prologue [] Nothing [],

M src/Render.hs => src/Render.hs +2 -1
@@ 121,6 121,7 @@ instance CSS.StyleSheet StyleAssets where
            )

downloadAssets session mimes (StyleAssets _ assets) =
    -- FIXME delete these temp files.
    forConcurrently assets (\uri ->
        fetchURL' session mimes uri >>= saveAsset mimes) >>=
        return . zip assets


@@ 134,7 135,7 @@ fetchURL' s m u = fetchURL s m u

saveAsset mimes (mime, download)
    | mime `notElem` mimes = return nullURI
    | otherwise = withSystemTempFile "rhapsode-asset" $ writeDownloadToFile download
    | otherwise = writeDownloadToFile download

rewritePropertyVal rewrites (CSSTok.Url text:vals)
    | Just uri <- parseURIReference $ Txt.unpack text, Just rewrite <- uri `M.lookup` rewrites =