From b34b2e2b7cefc9ca0cda6184273cf493da20f426 Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar <31743758+Akilan1999@users.noreply.github.com> Date: Fri, 10 Mar 2023 09:47:18 +0000 Subject: [PATCH] Change directory route and document change (#107) * changed route to view files added by a certain node * gofmt my changes * added fix for blockchain/explore to also accept localnodes as a parameter. * added local blockchain search --- search/Text 2 Hash.go | 48 +++++++++++++++++++++---------------------- webapi/Blockchain.go | 42 ++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/search/Text 2 Hash.go b/search/Text 2 Hash.go index 41edb1e..5343b3e 100644 --- a/search/Text 2 Hash.go +++ b/search/Text 2 Hash.go @@ -103,37 +103,37 @@ func hashWord(word string) (hash []byte, wordHashed string) { // // Examples // -// "" => [""] -// "lowercase" => ["lowercase"] -// "Class" => ["Class"] -// "MyClass" => ["My", "Class"] -// "MyC" => ["My", "C"] -// "HTML" => ["HTML"] -// "PDFLoader" => ["PDF", "Loader"] -// "AString" => ["A", "String"] -// "SimpleXMLParser" => ["Simple", "XML", "Parser"] -// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] -// "GL11Version" => ["GL", "11", "Version"] -// "99Bottles" => ["99", "Bottles"] -// "May5" => ["May", "5"] -// "BFG9000" => ["BFG", "9000"] -// "BöseÜberraschung" => ["Böse", "Überraschung"] -// "Two spaces" => ["Two", " ", "spaces"] -// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] +// "" => [""] +// "lowercase" => ["lowercase"] +// "Class" => ["Class"] +// "MyClass" => ["My", "Class"] +// "MyC" => ["My", "C"] +// "HTML" => ["HTML"] +// "PDFLoader" => ["PDF", "Loader"] +// "AString" => ["A", "String"] +// "SimpleXMLParser" => ["Simple", "XML", "Parser"] +// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] +// "GL11Version" => ["GL", "11", "Version"] +// "99Bottles" => ["99", "Bottles"] +// "May5" => ["May", "5"] +// "BFG9000" => ["BFG", "9000"] +// "BöseÜberraschung" => ["Böse", "Überraschung"] +// "Two spaces" => ["Two", " ", "spaces"] +// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] // // Splitting rules // -// 1) If string is not valid UTF-8, return it without splitting as -> removed in this fork. +// 1. If string is not valid UTF-8, return it without splitting as -> removed in this fork. // single item array. -// 2) Assign all unicode characters into one of 4 sets: lower case +// 2. Assign all unicode characters into one of 4 sets: lower case // letters, upper case letters, numbers, and all other characters. -// 3) Iterate through characters of string, introducing splits +// 3. Iterate through characters of string, introducing splits // between adjacent characters that belong to different sets. -// 4) Iterate through array of split strings, and if a given string +// 4. Iterate through array of split strings, and if a given string // is upper case: -// if subsequent string is lower case: -// move last character of upper case string to beginning of -// lower case string +// if subsequent string is lower case: +// move last character of upper case string to beginning of +// lower case string func CamelCaseSplit(src string) (entries []string) { entries = []string{} var runes [][]rune diff --git a/webapi/Blockchain.go b/webapi/Blockchain.go index 90e741d..ae6e6e3 100644 --- a/webapi/Blockchain.go +++ b/webapi/Blockchain.go @@ -7,9 +7,10 @@ Author: Peter Kleissner package webapi import ( - "encoding/hex" - "net/http" - "strconv" + "bytes" + "encoding/hex" + "net/http" + "strconv" "github.com/PeernetOfficial/core/blockchain" ) @@ -147,3 +148,38 @@ func (api *WebapiInstance) apiExploreNodeID(w http.ResponseWriter, r *http.Reque EncodeJSON(api.Backend, w, r, result) } + +/* +apiExploreNodeID returns the shared files of a particular node in Peernet. Results are returned in real-time. The file type is an optional filter. See TypeX. +Special type -2 = Binary, Compressed, Container, Executable. This special type includes everything except Documents, Video, Audio, Ebooks, Picture, Text. + +Request: GET /blockchain/view?limit=[max records]&type=[file type]&offset=[offset]&node=[node id] +Result: 200 with JSON structure SearchResult. Check the field status. +*/ +func (api *WebapiInstance) apiExploreNodeID(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + offset, _ := strconv.Atoi(r.Form.Get("offset")) + limit, err := strconv.Atoi(r.Form.Get("limit")) + if err != nil { + limit = 100 + } + // ID fields for results for a specific node ID. + NodeId, _ := DecodeBlake3Hash(r.Form.Get("node")) + + fileType, err := strconv.Atoi(r.Form.Get("type")) + if err != nil { + fileType = -1 + } + + // check if the node IDs are the same + if bytes.Compare(NodeId, api.Backend.SelfNodeID()) == 0 { + // setting the value of block to 0 + r.Form.Add("block", "0") + api.apiBlockchainRead(w, r) + return + } + + result := api.ExploreHelper(fileType, limit, offset, NodeId, true) + + EncodeJSON(api.Backend, w, r, result) +}