Created
June 23, 2022 05:22
-
-
Save epshteinmatthew/e1e79c57b00af5678666977c7055102b to your computer and use it in GitHub Desktop.
Start of a project i dont plan to continue.
This file contains hidden or 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
| package main | |
| import ( | |
| "crypto/sha256" | |
| "encoding/json" | |
| "fmt" | |
| "io/ioutil" | |
| "net/http" | |
| "os" | |
| "gorm.io/driver/sqlite" | |
| "gorm.io/gorm" | |
| ) | |
| type Image struct { | |
| gorm.Model | |
| Path string | |
| Location string | |
| Time string | |
| CCAP bool | |
| RURL string | |
| Caption string | |
| Vcode string | |
| } | |
| //verification struct | |
| //verification requests table, vcode is primary key | |
| //types of verification: Location, Time, caption checks out | |
| //first two, user can verify, other has to be a bystander | |
| //another way is reverse image search it, potentially display a link to the reverse search url if requested | |
| //Encrypted stuff: | |
| //send vcode hashed | |
| //get vcode from db | |
| //hash that, compare | |
| //return true if yes | |
| func findCodeFromHashed(hashed string, vCodes []string) string { | |
| //loop thru hashed array | |
| //return first instance of hashed string | |
| for i := 0; i < len(vCodes); i++ { | |
| if string(hashString(vCodes[i])) == hashed { | |
| return vCodes[i] | |
| } | |
| } | |
| return "None Found" | |
| } | |
| func findCodeFromDB(db *gorm.DB, hashed string) string{ | |
| var codes []string | |
| db.Select("Vcode").Find(&codes) | |
| return findCodeFromHashed(hashed, codes) | |
| } | |
| func folderCreation(name string) { | |
| os.Mkdir(name, 0750) | |
| //write to db in thread table | |
| } | |
| func hashString(plaintext string) []byte { | |
| h := sha256.New() | |
| h.Write([]byte(plaintext)) | |
| return h.Sum(nil) | |
| } | |
| func main() { | |
| imagesdb, err := gorm.Open(sqlite.Open("images.db"), &gorm.Config{}) | |
| if err != nil { | |
| panic("failed to connect database") | |
| } | |
| imagesdb.AutoMigrate(&Image{}) | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| fmt.Println("request from: " + r.Host) | |
| json.NewEncoder(w).Encode(Image{Path: "thread1/hello.jpeg", Location: "47.74097995252184, -122.22272509565296", Caption: "A fun thingy"}) | |
| }) | |
| http.HandleFunc("/images", func(w http.ResponseWriter, r *http.Request) { | |
| fileBytes, err := ioutil.ReadFile("/home/matthew/Documents/locker/images/" + r.URL.Query()["path"][0]) | |
| if err != nil { | |
| panic(err) | |
| } | |
| w.WriteHeader(http.StatusOK) | |
| w.Header().Set("Content-Type", "application/octet-stream") | |
| w.Write(fileBytes) | |
| }) | |
| http.ListenAndServe(":4200", nil) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment