-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump server version to 2.20.0.0 * Add append endpoint to Web API * Add DirectoryName and FileName modules * Append endpoint DAG surgery (#608) * Implement add file to app endpoint * Add some notes to the readme * Rewrite IPFS files stats to handle more than CIDs * Use multipart upload instead of octetstream * Retrieve domain and update DNSLink * Use domain name from ENV * Append to uploads directory * Return CID of appended file * Validate UCAN resource (#621) Co-authored-by: Steven Vandevelde <[email protected]>
- Loading branch information
Showing
33 changed files
with
842 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Fission.FileSystem.DirectoryName (module Fission.FileSystem.DirectoryName.Types) where | ||
|
||
import Fission.FileSystem.DirectoryName.Types |
13 changes: 13 additions & 0 deletions
13
fission-core/library/Fission/FileSystem/DirectoryName/Error.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- | Directory name errors | ||
module Fission.FileSystem.DirectoryName.Error (Invalid (..)) where | ||
|
||
import Fission.Prelude | ||
|
||
data Invalid = Invalid | ||
deriving ( Show | ||
, Eq | ||
, Exception | ||
) | ||
|
||
instance Display Invalid where | ||
display Invalid = "Invalid directory name -- must be alphanumeric separated with hyphens and not blocklisted" |
44 changes: 44 additions & 0 deletions
44
fission-core/library/Fission/FileSystem/DirectoryName/Types.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Fission.FileSystem.DirectoryName.Types (DirectoryName (..)) where | ||
|
||
import RIO.Text as Text | ||
|
||
import Data.Swagger | ||
import Servant.API | ||
|
||
import Fission.Prelude | ||
|
||
import Fission.URL.Validation | ||
|
||
import Fission.FileSystem.DirectoryName.Error | ||
|
||
newtype DirectoryName = DirectoryName { directoryName :: Text } | ||
deriving ( Generic ) | ||
deriving anyclass ( ToSchema | ||
, ToParamSchema | ||
) | ||
deriving newtype ( Eq | ||
, Show | ||
, IsString | ||
) | ||
|
||
mkDirectoryName :: Text -> Either Invalid DirectoryName | ||
mkDirectoryName txt = | ||
if isValid normalized | ||
then Right $ DirectoryName normalized | ||
else Left Invalid | ||
|
||
where | ||
normalized = Text.toLower txt | ||
|
||
instance Arbitrary DirectoryName where | ||
arbitrary = do | ||
txt <- arbitrary | ||
case mkDirectoryName $ Text.filter isURLChar txt of | ||
Left _ -> arbitrary | ||
Right dName -> return dName | ||
|
||
instance FromHttpApiData DirectoryName where | ||
parseUrlPiece = Right . DirectoryName | ||
|
||
instance ToHttpApiData DirectoryName where | ||
toUrlPiece (DirectoryName directoryName) = directoryName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Fission.FileSystem.FileName (module Fission.FileSystem.FileName.Types) where | ||
|
||
import Fission.FileSystem.FileName.Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- | File name errors | ||
module Fission.FileSystem.FileName.Error (Invalid (..)) where | ||
|
||
import Fission.Prelude | ||
|
||
data Invalid = Invalid | ||
deriving ( Show | ||
, Eq | ||
, Exception | ||
) | ||
|
||
instance Display Invalid where | ||
display Invalid = "Invalid file name -- must be alphanumeric separated with hyphens and not blocklisted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Fission.FileSystem.FileName.Types (FileName (..)) where | ||
|
||
import RIO.Text as Text | ||
|
||
import Data.Swagger | ||
import Servant.API | ||
|
||
import Fission.Prelude | ||
|
||
import Fission.URL.Validation | ||
|
||
import Fission.FileSystem.FileName.Error | ||
|
||
|
||
newtype FileName = FileName { fileName :: Text } | ||
deriving ( Generic ) | ||
deriving anyclass ( ToSchema | ||
, ToParamSchema | ||
) | ||
deriving newtype ( Eq | ||
, Show | ||
, IsString | ||
) | ||
|
||
mkDirectoryName :: Text -> Either Invalid FileName | ||
mkDirectoryName txt = | ||
if isValid normalized | ||
then Right $ FileName normalized | ||
else Left Invalid | ||
|
||
where | ||
normalized = Text.toLower txt | ||
|
||
instance Arbitrary FileName where | ||
arbitrary = do | ||
txt <- arbitrary | ||
case mkDirectoryName $ Text.filter isURLChar txt of | ||
Left _ -> arbitrary | ||
Right dName -> return dName | ||
|
||
instance FromHttpApiData FileName where | ||
parseUrlPiece = Right . FileName | ||
|
||
instance ToHttpApiData FileName where | ||
toUrlPiece (FileName fileName) = fileName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Fission.Web.API.Append.Types (RoutesV2 (..)) where | ||
|
||
import Network.IPFS.File.Types as File | ||
import Network.IPFS.CID.Types | ||
|
||
import Fission.Web.API.Prelude | ||
|
||
import qualified Fission.Web.API.Auth.Types as Auth | ||
|
||
import Fission.FileSystem.DirectoryName.Types as DirectoryName | ||
import Fission.FileSystem.FileName.Types as FileName | ||
|
||
newtype RoutesV2 mode = RoutesV2 | ||
{ append :: | ||
mode | ||
:- Summary "Append a file" | ||
:> Description "Append a file to an app's public upload directory" | ||
-- | ||
:> Capture "App Name" DirectoryName | ||
:> Capture "File Name" FileName | ||
-- | ||
:> ReqBody '[OctetStream] Serialized | ||
-- | ||
:> Auth.HigherOrder | ||
:> PutAccepted '[JSON] CID | ||
} | ||
deriving Generic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.