示例#1
0
func (a appsscriptservice) GetBlob(h objects.HCID) (b objects.Blob, err error) {
	quarryurl := fmt.Sprintf(
		"%s%s%s%s%s%s",
		"https://",
		"script.google.com",
		"/macros/s/AKfycbzl2R7UR2FGGVdgl_WbKabbIoku66ELRSnQ4pbkmBgDdWWvgh8b/exec?",
		//"/macros/s/AKfycbxyU7ABEmq4HS_8nb7E5ZbtJKRwuVlLBwnhUJ4VjSH0/dev?",
		"type=blob",
		"&hcid=",
		h.Hex(),
	)
	//log.Println(quarryurl)
	resp, err := http.Get(quarryurl)
	if err != nil {
		return b, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return b, err
	}
	data, err := base64.StdEncoding.DecodeString(string(body))
	if err != nil {
		log.Printf("%s\n", body)
		log.Println("error:", err)
		return nil, err
	}
	return data, err
}
示例#2
0
func (k kademliaservice) GetBlob(h objects.HCID) (b objects.Blob, err error) {
	values := url.Values{}
	values.Add("type", "blob")
	values.Add("hcid", h.Hex())
	data, err := k.getobject(values)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	return data, err
}
示例#3
0
func (indexEntry blobIndexEntry) insertDescendant(
	versionNumber int64,
	descendantHCID objects.HCID,
) blobIndexEntry {
	if indexEntry.Descendants == nil {
		indexEntry.Descendants = make(map[int64]string)
	}
	if _, present := indexEntry.Descendants[versionNumber]; !present {
		indexEntry.Descendants[versionNumber] = descendantHCID.Hex()
	}
	return indexEntry
}
示例#4
0
func (m multicastservice) GetBlob(h objects.HCID) (b objects.Blob, err error) {
	message := fmt.Sprintf("{\"type\":\"blob\", \"hcid\": \"%s\"}", h.Hex())
	blobchannel := make(chan objects.Blob, 1)
	m.waitingforblob[h.Hex()] = blobchannel
	m.sendmessage(message)
	select {
	case b = <-blobchannel:
		return b, err

	case <-time.After(150 * time.Millisecond):
		//log.Printf("Timing out now")
		return b, fmt.Errorf("GetBlob on Multicast service timed out")
	}
}
示例#5
0
func (gds googledriveservice) GetBlob(h objects.HCID) (objects.Blob, error) {

	if gds.driveService == nil {
		return nil, fmt.Errorf("Drive Service not initialized")
	}
	fileID, err := gds.getChildWithTitle(gds.blobsFolderID, h.Hex())
	f, err := gds.driveService.Files.Get(fileID).Do()
	fileString, err := gds.DownloadFile(f)
	if err != nil {
		log.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	log.Printf("Blob %s:\n%q", h, fileString)
	return objects.Blob(fileString), err
}
示例#6
0
func (d directhttpservice) GetBlob(h objects.HCID) (objects.Blob, error) {
	for _, host := range hosts {
		quarryurl := fmt.Sprintf(
			"https://%s/b/%s",
			host,
			h.Hex(),
		)
		body, err := urlReadAll(quarryurl)
		if err != nil {
			return objects.Blob{}, err
		}
		return objects.Blob(body), err
	}
	return objects.Blob{}, fmt.Errorf("No Hosts")
}
示例#7
0
func makeURL(hkid objects.HKID, hcid objects.HCID, typeString string, nameSegment string, version int64) (response string) {
	//Path
	if typeString == "blob" {
		response = fmt.Sprintf("/b/%s" /*host,*/, hcid.Hex())
	} else if typeString == "commit" {
		response = fmt.Sprintf("/c/%s/%d" /*host,*/, hkid.Hex(), version)
	} else if typeString == "tag" {
		response = fmt.Sprintf("/t/%s/%s/%d" /*host,*/, hkid.Hex(), nameSegment, version)
	} else if typeString == "key" {
		response = fmt.Sprintf("/k/%s" /*host,*/, hkid.Hex())
	} else {
		response = ""
	}
	return response
}
示例#8
0
func (lfs localfileservice) GetBlob(h objects.HCID) (b objects.Blob, err error) {
	//ToDo Validate input
	if h == nil {
		return nil, fmt.Errorf("[localfileservice] GetBlob() HCID is nil")
	}
	filepath := fmt.Sprintf("bin/blobs/%s", h.Hex())
	//log.Printf("Filepath: %v", filepath)
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		//log.Printf("\n\t%v\n", err)
		return
	}
	//build object
	b = objects.Blob(data)
	return b, err
}
示例#9
0
func buildResponse(hkid objects.HKID, hcid objects.HCID, typeString string, nameSegment string, version int64) (response string) {
	if typeString == "blob" {
		response = fmt.Sprintf("{\"type\": \"blob\", \"hcid\": \"%s\", \"URL\": \"%s\"}", hcid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "commit" {
		response = fmt.Sprintf("{\"type\": \"commit\",\"hkid\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "tag" {
		response = fmt.Sprintf("{\"type\": \"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(), nameSegment,
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "key" {
		response = fmt.Sprintf("{\"type\": \"key\",\"hkid\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else {
		return ""
	}
	return response

}