generalizes

This commit is contained in:
Aaron Greenspan
2020-01-05 23:09:13 -07:00
parent f341f8ebaf
commit 5bbf48b8c4
6 changed files with 13 additions and 24 deletions

View File

@@ -4,14 +4,10 @@
/version VersionR GET /version VersionR GET
/apps/version/#Text VersionAppR GET --get most recent appId version /apps/version/#Text VersionAppR GET --get most recent appId version
/sys/version/agent VersionAgentR GET --get most recent agent version /sys/version/#Text VersionSysR GET --get most recent sys app version
/sys/version/appmgr VersionAppMgrR GET --get most recent appmgr version
/sys/version/torrc VersionTorrcR GET --get most recent torrc version
/icons/#PNG IconsR GET -- get icons /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} !/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/#SYS_EXTENSIONLESS SysR GET --get most recent sys app -- ?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.tar.gz ImageR GET --get most recent iso image, ?spec={semver-spec} /sys.tar.gz ImageR GET --get most recent iso image, ?spec={semver-spec}

View File

@@ -12,7 +12,7 @@ sslPath :: FilePath
sslPath = "/var/ssl" sslPath = "/var/ssl"
resourcesDir :: FilePath resourcesDir :: FilePath
resourcesDir = "/var/www/html/resources" resourcesDir = "./resources" --"/var/www/html/resources"
registryVersion :: AppVersion registryVersion :: AppVersion
registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version

View File

@@ -42,14 +42,8 @@ getAppsManifestR = respondSource typePlain $ CB.sourceFile appManifestPath .| aw
getImageR :: Handler TypedContent getImageR :: Handler TypedContent
getImageR = getApp resourcesDir ("sys" :: Extension "tar.gz") getImageR = getApp resourcesDir ("sys" :: Extension "tar.gz")
getAgentR :: Handler TypedContent getSysR :: Extension "" -> Handler TypedContent
getAgentR = getApp sysResourceDir ("agent" :: Extension "") getSysR = getApp sysResourceDir
getAppMgrR :: Handler TypedContent
getAppMgrR = getApp sysResourceDir ("appmgr" :: Extension "")
getTorrcR :: Handler TypedContent
getTorrcR = getApp sysResourceDir ("torrc" :: Extension "")
getAppR :: Extension "s9pk" -> Handler TypedContent getAppR :: Extension "s9pk" -> Handler TypedContent
getAppR = getApp appResourceDir getAppR = getApp appResourceDir

View File

@@ -21,14 +21,10 @@ getVersionAppR appId = getVersionWSpec appResourceDir appExt
where where
appExt = Extension (toS appId) :: Extension "s9pk" appExt = Extension (toS appId) :: Extension "s9pk"
getVersionAgentR :: Handler (Maybe AppVersionRes) getVersionSysR :: Text -> Handler (Maybe AppVersionRes)
getVersionAgentR = getVersionWSpec sysResourceDir ("agent" :: Extension "") getVersionSysR sysAppId = getVersionWSpec sysResourceDir sysExt
where
getVersionAppMgrR :: Handler (Maybe AppVersionRes) sysExt = Extension (toS sysAppId) :: Extension ""
getVersionAppMgrR = getVersionWSpec sysResourceDir ("appmgr" :: Extension "")
getVersionTorrcR :: Handler (Maybe AppVersionRes)
getVersionTorrcR = getVersionWSpec sysResourceDir ("torrc" :: Extension "")
getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe AppVersionRes) getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe AppVersionRes)
getVersionWSpec rootDir ext = do getVersionWSpec rootDir ext = do

View File

@@ -64,6 +64,7 @@ getUnversionedFileFromDir rootDirectory appExt = fmap (join . hush) . try @SomeE
newtype Extension (a :: Symbol) = Extension String deriving (Eq) newtype Extension (a :: Symbol) = Extension String deriving (Eq)
type S9PK = Extension "s9pk" type S9PK = Extension "s9pk"
type SYS_EXTENSIONLESS = Extension ""
type PNG = Extension "png" type PNG = Extension "png"
instance IsString (Extension a) where instance IsString (Extension a) where
@@ -83,7 +84,9 @@ instance KnownSymbol a => Read (Extension a) where
where where
m = length s m = length s
ext' = extension (def :: Extension a) 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 instance KnownSymbol a => PathPiece (Extension a) where
fromPathPiece = readMaybe . toS fromPathPiece = readMaybe . toS