amuse.git

commit 88ea87016a5438a6ff1b796d55bd5928c2764493

Author: Adam <git@apiote.tk>

not use outside service for empty avatar

 libamuse/user.go | 53 ++++++--------------------------------------
 static/img/avatar.svg | 14 +++++++++++


diff --git a/libamuse/user.go b/libamuse/user.go
index 3c26306818b7c84cfae7179c873a43b9b234ee8a..2cdfeee34c784d522a169312b7b74cbf8ef8f60a 100644
--- a/libamuse/user.go
+++ b/libamuse/user.go
@@ -2,13 +2,13 @@ package libamuse
 
 import (
 	"notabug.org/apiote/amuse/accounts"
+	"notabug.org/apiote/amuse/config"
 	"notabug.org/apiote/amuse/db"
-	"notabug.org/apiote/amuse/network"
 
 	"crypto/sha256"
 	"encoding/base64"
 	"errors"
-	"net/http"
+	"io/ioutil"
 
 	"notabug.org/apiote/gott"
 )
@@ -52,7 +52,7 @@ func checkEtag(args ...interface{}) (interface{}, error) {
 	request := args[0].(*RequestData)
 	result := args[1].(*Result)
 	h := sha256.New()
-	_, err := h.Write([]byte(result.page))
+	_, err := h.Write(result.result.([]byte))
 	if err != nil {
 		return gott.Tuple(args), err
 	}
@@ -64,26 +64,6 @@ 	result.page = etag
 	return gott.Tuple(args), nil
 }
 
-func createPlaceholderRequest(args ...interface{}) (interface{}, error) {
-	request := args[0].(*network.Request)
-	result := args[1].(*network.Result)
-	small := args[2].(bool)
-	result.Client = &http.Client{}
-	size := "512"
-	if small {
-		size = "40"
-	}
-	httpRequest, err := http.NewRequest("GET", "https://api.adorable.io/avatars/"+size+"/"+request.Id+".png", nil)
-	result.Request = httpRequest
-	return gott.Tuple(args), err
-}
-
-func unmarshalPlaceholder(args ...interface{}) interface{} {
-	result := args[1].(*network.Result)
-	result.Result = result.Body
-	return gott.Tuple(args)
-}
-
 func recovery(args ...interface{}) (interface{}, error) {
 	err := args[3].(error)
 	switch err.Error() {
@@ -95,28 +75,11 @@ 	}
 }
 
 func getPlaceholder(args ...interface{}) (interface{}, error) {
-	request := args[0].(*RequestData)
 	result := args[1].(*Result)
-	small := args[2].(bool)
-	r, err := gott.
-		NewResult(gott.Tuple{&network.Request{Id: request.id, Etag: request.etag}, &network.Result{}, small}).
-		Bind(createPlaceholderRequest).
-		Map(network.AddHeaders).
-		Bind(network.DoRequest).
-		Bind(network.HandleRequestError).
-		Bind(network.ReadResponse).
-		Map(unmarshalPlaceholder).
-		// todo get etag
-		Finish()
-
-	if err != nil {
-		return gott.Tuple(args), err
-	}
-
-	result.result = r.(gott.Tuple)[1].(*network.Result).Result.([]byte)
-	result.result2 = "image/png"
-
-	return gott.Tuple(args), nil
+	img, err := ioutil.ReadFile(config.DataHome + "/static/img/avatar.webp") // todo path
+	result.result = img
+	result.result2 = "image/webp"
+	return gott.Tuple(args), err
 }
 
 func ShowUserAvatar(username, etagReq string, auth accounts.Authentication, small bool) (Avatar, error) {
@@ -129,8 +92,8 @@ 		Bind(verifyToken).
 		Bind(verifyUser).
 		Bind(getUser).
 		Bind(getAvatar).
-		Bind(checkEtag).
 		Recover(recovery).
+		Bind(checkEtag).
 		Finish()
 
 	if err != nil {




diff --git a/static/img/avatar.svg b/static/img/avatar.svg
new file mode 100644
index 0000000000000000000000000000000000000000..a169ddac038ce7ce8cda194c2b83cc8de912bd36
--- /dev/null
+++ b/static/img/avatar.svg
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="126.67" height="126.67" version="1.1" viewBox="0 0 126.67 126.67" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <metadata>
+  <rdf:RDF>
+   <cc:Work rdf:about="">
+    <dc:format>image/svg+xml</dc:format>
+    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+    <dc:title/>
+   </cc:Work>
+  </rdf:RDF>
+ </metadata>
+ <path d="m52.875 66.367c-6.438-6.0318-11.219-11.449-10.624-12.038 0.59506-0.58892 3.4819-1.2629 6.4153-1.4977l5.3333-0.42693 0.84896-14.823c0.46693-8.1525 1.5184-17.698 2.3367-21.213 0.81826-3.5148 1.3362-7.1531 1.151-8.0851-0.23731-1.1944 1.7938-1.6946 6.8801-1.6946 6.7051 0 7.2445 0.23887 7.6068 3.3688 0.21445 1.8528 1.2705 11.689 2.3468 21.857 1.0763 10.169 2.3643 19.155 2.8622 19.969 0.49794 0.81425 3.2187 1.3116 6.0462 1.1053 2.8275-0.20632 5.5849 0.07358 6.1275 0.62199 1.3209 1.335-20.913 23.822-23.553 23.822-1.1399 0-7.34-4.935-13.778-10.966z" fill="#96bee4" stroke-width="1.3404"/>
+ <path d="m0 63.333v-63.333h126.67v126.67h-126.67zm76.919 51.248c8.4782-7.1626 14.605-14.118 17.834-20.248 1.4489-2.75 3.1879-5 3.8645-5 0.67654 0 4.5643-4.2613 8.6396-9.4696 6.0361-7.7144 7.4095-10.411 7.4095-14.548 0-4.0341-0.84366-5.7884-4.1023-8.5304-2.2563-1.8985-4.9563-3.4519-6-3.4519-1.4059 0-1.8977-1.8565-1.8977-7.1638 0-11.588-8.9008-28.638-17.622-33.756-6.5374-3.8365-16.319-6.1755-22.78-5.4473-8.3939 0.94612-21.72 7.3942-26.476 12.811-5.727 6.5227-9.0581 14.444-9.0928 21.622-0.03257 6.7476-1.7357 9.2667-6.2652 9.2667-3.6271 0-6.4625 4.0886-7.692 11.092-0.6856 3.905-0.24814 6.1862 1.8771 9.7882 4.0132 6.8019 11.125 15.068 12.989 15.096 0.88235 0.0132 2.8631 2.874 4.4016 6.3574 3.3416 7.5656 8.9523 13.68 17.994 19.61 14.54 9.5354 17.692 9.7663 26.919 1.9714z" fill="#da9d3c" stroke-width="1.3333"/>
+</svg>