Skip to content

Commit

Permalink
Merge pull request #38 from jonschoning/non-http-url-schemes
Browse files Browse the repository at this point in the history
add setting ALLOW_NON_HTTP_URL_SCHEMES
  • Loading branch information
jonschoning committed Apr 27, 2022
2 parents 2986230 + e7636cc commit 368c5db
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__v0.0.13__
add setting ALLOW_NON_HTTP_URL_SCHEMES (default false)

__v0.0.12__
update to ghc9

Expand Down
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ archive-socks-proxy-port: "_env:ARCHIVE_SOCKS_PROXY_PORT"
source-code-uri: "_env:SOURCE_CODE_URI:https://github.com/jonschoning/espial"

ssl-only: "_env:SSL_ONLY" # false

allow-non-http-url-schemes: "_env:ALLOW_NON_HTTP_URL_SCHEMES:false"
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ services:
environment:
- IP_FROM_HEADER=true
- SQLITE_DATABASE=/app/data/espial.sqlite3
# - DETAILED_LOGGING=true
# - SHOULD_LOG_ALL=true
# - SSL_ONLY=false
# - DETAILED_LOGGING=false
# - SHOULD_LOG_ALL=false
# - ARCHIVE_SOCKS_PROXY_HOST=localhost
# - ARCHIVE_SOCKS_PROXY_PORT=8888
# - SOURCE_CODE_URI=https://github.com/jonschoning/espial
# - ALLOW_NON_HTTP_URL_SCHEMES=false
2 changes: 1 addition & 1 deletion espial.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: espial
version: 0.0.12
version: 0.0.13
synopsis: Espial is an open-source, web-based bookmarking server.
description: .
Espial is an open-source, web-based bookmarking server.
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: espial
synopsis: Espial is an open-source, web-based bookmarking server.
version: "0.0.12"
version: "0.0.13"
description: ! '
Espial is an open-source, web-based bookmarking server.
Expand Down
9 changes: 5 additions & 4 deletions src/Handler/Add.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ postAddR = do
_handleFormSuccess :: BookmarkForm -> Handler (UpsertResult (Key Bookmark))
_handleFormSuccess bookmarkForm = do
(userId, user) <- requireAuthPair
case (parseRequest . unpack . _url) bookmarkForm of
Nothing -> pure $ Failed "Invalid URL"
Just _ -> do
appSettings <- appSettings <$> getYesod
case (appAllowNonHttpUrlSchemes appSettings, (parseRequest . unpack . _url) bookmarkForm) of
(False, Nothing) -> pure $ Failed "Invalid URL"
(_, _) -> do
let mkbid = BookmarkKey <$> _bid bookmarkForm
tags = maybe [] (nub . words . T.replace "," " ") (_tags bookmarkForm)
bm <- liftIO $ _toBookmark userId bookmarkForm
res <- runDB (upsertBookmark userId mkbid bm tags)
forM_ (maybeUpsertResult res) $ \kbid ->
whenM (shouldArchiveBookmark user kbid) $
void $ async (archiveBookmarkUrl kbid (unpack (bookmarkHref bm)))
void $ async (archiveBookmarkUrl kbid (unpack (bookmarkHref bm)))
pure res

postLookupTitleR :: Handler ()
Expand Down
4 changes: 4 additions & 0 deletions src/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ data AppSettings = AppSettings
-- ^ Uri to app source code

, appSSLOnly :: Bool

, appAllowNonHttpUrlSchemes :: Bool
}

instance FromJSON AppSettings where
Expand Down Expand Up @@ -102,6 +104,8 @@ instance FromJSON AppSettings where

appSSLOnly <- fromMaybe False <$> o .:? "ssl-only"

appAllowNonHttpUrlSchemes <- fromMaybe False <$> o .:? "allow-non-http-url-schemes"

return AppSettings {..}

-- | Settings for 'widgetFile', such as which template languages to support and
Expand Down

0 comments on commit 368c5db

Please sign in to comment.