mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-04-18 02:33:10 +00:00
adds Torrent BlockType
This commit is contained in:
parent
6938ba203d
commit
e4a04f37da
@ -134,6 +134,12 @@ func mimetype*(self: Manifest): ?string =
|
||||
# Operations on block list
|
||||
############################################################
|
||||
|
||||
func isTorrentInfoHash*(cid: Cid): ?!bool =
|
||||
success (InfoHashV1Codec == ?cid.contentType().mapFailure(CodexError))
|
||||
|
||||
func isTorrentInfoHash*(mc: MultiCodec): ?!bool =
|
||||
success (mc == InfoHashV1Codec)
|
||||
|
||||
func isManifest*(cid: Cid): ?!bool =
|
||||
success (ManifestCodec == ?cid.contentType().mapFailure(CodexError))
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ type
|
||||
BlockNotFoundError* = object of CodexError
|
||||
|
||||
BlockType* {.pure.} = enum
|
||||
Torrent
|
||||
Manifest
|
||||
Block
|
||||
Both
|
||||
|
||||
@ -166,8 +166,10 @@ method listBlocks*(
|
||||
return true
|
||||
of BlockType.Manifest:
|
||||
return isManifest
|
||||
of BlockType.Torrent:
|
||||
return isTorrent
|
||||
of BlockType.Block:
|
||||
return not isManifest
|
||||
return not (isManifest or isTorrent)
|
||||
)
|
||||
)
|
||||
success(iter)
|
||||
|
||||
@ -24,6 +24,7 @@ const
|
||||
CodexBlocksKey* = Key.init(CodexBlocksNamespace).tryGet
|
||||
CodexTotalBlocksKey* = Key.init(CodexBlockTotalNamespace).tryGet
|
||||
CodexManifestKey* = Key.init(CodexManifestNamespace).tryGet
|
||||
TorrentInfoHashKey* = Key.init(TorrentInfoHashNamespace).tryGet
|
||||
BlocksTtlKey* = Key.init(CodexBlocksTtlNamespace).tryGet
|
||||
BlockProofKey* = Key.init(CodexBlockProofNamespace).tryGet
|
||||
QuotaKey* = Key.init(CodexQuotaNamespace).tryGet
|
||||
@ -33,7 +34,9 @@ const
|
||||
func makePrefixKey*(postFixLen: int, cid: Cid): ?!Key =
|
||||
let cidKey = ?Key.init(($cid)[^postFixLen ..^ 1] & "/" & $cid)
|
||||
|
||||
if ?cid.isManifest:
|
||||
if ?cid.isTorrentInfoHash:
|
||||
success TorrentInfoHashKey / cidKey
|
||||
elif ?cid.isManifest:
|
||||
success CodexManifestKey / cidKey
|
||||
else:
|
||||
success CodexBlocksKey / cidKey
|
||||
|
||||
@ -304,6 +304,7 @@ method listBlocks*(
|
||||
|
||||
let key =
|
||||
case blockType
|
||||
of BlockType.Torrent: TorrentInfoHashKey
|
||||
of BlockType.Manifest: CodexManifestKey
|
||||
of BlockType.Block: CodexBlocksKey
|
||||
of BlockType.Both: CodexRepoKey
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user