From 5bbf48b8c48ba55e66024619ae173aa5a79e2aaf Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Sun, 5 Jan 2020 23:09:13 -0700 Subject: [PATCH 1/3] generalizes --- config/routes | 8 ++------ .../sys/appmgr/0.0.0/{appmgr.deleteme => appmgr} | 0 src/Constants.hs | 2 +- src/Handler/Apps.hs | 10 ++-------- src/Handler/Version.hs | 12 ++++-------- src/Lib/Registry.hs | 5 ++++- 6 files changed, 13 insertions(+), 24 deletions(-) rename resources/sys/appmgr/0.0.0/{appmgr.deleteme => appmgr} (100%) diff --git a/config/routes b/config/routes index 8045cf3..8af72cc 100644 --- a/config/routes +++ b/config/routes @@ -4,14 +4,10 @@ /version VersionR GET /apps/version/#Text VersionAppR GET --get most recent appId version -/sys/version/agent VersionAgentR GET --get most recent agent version -/sys/version/appmgr VersionAppMgrR GET --get most recent appmgr version -/sys/version/torrc VersionTorrcR GET --get most recent torrc version +/sys/version/#Text VersionSysR GET --get most recent sys app version /icons/#PNG IconsR GET -- get icons !/apps/#S9PK AppR GET --get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec} -/sys/agent AgentR GET --get most recent agent at appversion -- ?spec={semver-spec} -/sys/appmgr AppMgrR GET --get most recent appmgr at appversion -- ?spec={semver-spec} -/sys/torrc TorrcR GET --get most recent torrc at appversion -- ?spec={semver-spec} +!/sys/#SYS_EXTENSIONLESS SysR GET --get most recent sys app -- ?spec={semver-spec} /sys.tar.gz ImageR GET --get most recent iso image, ?spec={semver-spec} \ No newline at end of file diff --git a/resources/sys/appmgr/0.0.0/appmgr.deleteme b/resources/sys/appmgr/0.0.0/appmgr similarity index 100% rename from resources/sys/appmgr/0.0.0/appmgr.deleteme rename to resources/sys/appmgr/0.0.0/appmgr diff --git a/src/Constants.hs b/src/Constants.hs index 62c2f80..fcd78f1 100644 --- a/src/Constants.hs +++ b/src/Constants.hs @@ -12,7 +12,7 @@ sslPath :: FilePath sslPath = "/var/ssl" resourcesDir :: FilePath -resourcesDir = "/var/www/html/resources" +resourcesDir = "./resources" --"/var/www/html/resources" registryVersion :: AppVersion registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index eb29d26..bc17f55 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -42,14 +42,8 @@ getAppsManifestR = respondSource typePlain $ CB.sourceFile appManifestPath .| aw getImageR :: Handler TypedContent getImageR = getApp resourcesDir ("sys" :: Extension "tar.gz") -getAgentR :: Handler TypedContent -getAgentR = getApp sysResourceDir ("agent" :: Extension "") - -getAppMgrR :: Handler TypedContent -getAppMgrR = getApp sysResourceDir ("appmgr" :: Extension "") - -getTorrcR :: Handler TypedContent -getTorrcR = getApp sysResourceDir ("torrc" :: Extension "") +getSysR :: Extension "" -> Handler TypedContent +getSysR = getApp sysResourceDir getAppR :: Extension "s9pk" -> Handler TypedContent getAppR = getApp appResourceDir diff --git a/src/Handler/Version.hs b/src/Handler/Version.hs index e1cf92d..7860580 100644 --- a/src/Handler/Version.hs +++ b/src/Handler/Version.hs @@ -21,14 +21,10 @@ getVersionAppR appId = getVersionWSpec appResourceDir appExt where appExt = Extension (toS appId) :: Extension "s9pk" -getVersionAgentR :: Handler (Maybe AppVersionRes) -getVersionAgentR = getVersionWSpec sysResourceDir ("agent" :: Extension "") - -getVersionAppMgrR :: Handler (Maybe AppVersionRes) -getVersionAppMgrR = getVersionWSpec sysResourceDir ("appmgr" :: Extension "") - -getVersionTorrcR :: Handler (Maybe AppVersionRes) -getVersionTorrcR = getVersionWSpec sysResourceDir ("torrc" :: Extension "") +getVersionSysR :: Text -> Handler (Maybe AppVersionRes) +getVersionSysR sysAppId = getVersionWSpec sysResourceDir sysExt + where + sysExt = Extension (toS sysAppId) :: Extension "" getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe AppVersionRes) getVersionWSpec rootDir ext = do diff --git a/src/Lib/Registry.hs b/src/Lib/Registry.hs index e9838b8..7df0616 100644 --- a/src/Lib/Registry.hs +++ b/src/Lib/Registry.hs @@ -64,6 +64,7 @@ getUnversionedFileFromDir rootDirectory appExt = fmap (join . hush) . try @SomeE newtype Extension (a :: Symbol) = Extension String deriving (Eq) type S9PK = Extension "s9pk" +type SYS_EXTENSIONLESS = Extension "" type PNG = Extension "png" instance IsString (Extension a) where @@ -83,7 +84,9 @@ instance KnownSymbol a => Read (Extension a) where where m = length s ext' = extension (def :: Extension a) - n = length ext' + n = if length ext' == 0 + then -1 + else length ext' instance KnownSymbol a => PathPiece (Extension a) where fromPathPiece = readMaybe . toS From 2575e84f0ed969897dc70b354109af8d5fe6ea5f Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Sun, 5 Jan 2020 23:42:43 -0700 Subject: [PATCH 2/3] cleans up read instance considerably --- src/Lib/Registry.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Lib/Registry.hs b/src/Lib/Registry.hs index 7df0616..9b42c91 100644 --- a/src/Lib/Registry.hs +++ b/src/Lib/Registry.hs @@ -14,8 +14,6 @@ import System.Directory import System.FilePath import Yesod.Core -import Data.Text (isSuffixOf) - import Constants import Lib.Semver import Lib.Types.Semver @@ -80,13 +78,16 @@ instance KnownSymbol a => Show (Extension a) where show e@(Extension file) = file <.> extension e instance KnownSymbol a => Read (Extension a) where - readsPrec _ s = [(Extension . take (m - n - 1) $ s, "") | toS ext' `isSuffixOf` toS s] + readsPrec _ s = [(Extension fileName, "") | ("" <.> fileExt) == ("" <.> ext')] where - m = length s + (fileName, fileExt) = splitExtension s ext' = extension (def :: Extension a) - n = if length ext' == 0 - then -1 - else length ext' + +withPeriod :: String -> String +withPeriod word@(a:_) = case a of + '.' -> word + _ -> "." <> word +withPeriod word = word instance KnownSymbol a => PathPiece (Extension a) where fromPathPiece = readMaybe . toS From f735a80e8188dab3578bd83f36b999464e974783 Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Mon, 6 Jan 2020 23:22:18 -0700 Subject: [PATCH 3/3] fix resourcesDir --- src/Constants.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Constants.hs b/src/Constants.hs index fcd78f1..261d480 100644 --- a/src/Constants.hs +++ b/src/Constants.hs @@ -12,7 +12,7 @@ sslPath :: FilePath sslPath = "/var/ssl" resourcesDir :: FilePath -resourcesDir = "./resources" --"/var/www/html/resources" +resourcesDir = "/var/www/html/resources" -- "./resources" -- registryVersion :: AppVersion registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version