func restGetDeviceID(w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() idStr := qs.Get("id") id, err := protocol.DeviceIDFromString(idStr) w.Header().Set("Content-Type", "application/json; charset=utf-8") if err == nil { json.NewEncoder(w).Encode(map[string]string{ "id": id.String(), }) } else { json.NewEncoder(w).Encode(map[string]string{ "error": err.Error(), }) } }
func restGetCompletion(m *model.Model, w http.ResponseWriter, r *http.Request) { var qs = r.URL.Query() var folder = qs.Get("folder") var deviceStr = qs.Get("device") device, err := protocol.DeviceIDFromString(deviceStr) if err != nil { http.Error(w, err.Error(), 500) return } res := map[string]float64{ "completion": m.Completion(device, folder), } w.Header().Set("Content-Type", "application/json; charset=utf-8") json.NewEncoder(w).Encode(res) }
func main() { log.SetFlags(0) log.SetOutput(os.Stdout) folder := flag.String("folder", "default", "Folder ID") device := flag.String("device", "", "Device ID (blank for global)") flag.Parse() db, err := leveldb.OpenFile(flag.Arg(0), nil) if err != nil { log.Fatal(err) } fs := files.NewSet(*folder, db) if *device == "" { log.Printf("*** Global index for folder %q", *folder) fs.WithGlobalTruncated(func(fi protocol.FileIntf) bool { f := fi.(protocol.FileInfoTruncated) fmt.Println(f) fmt.Println("\t", fs.Availability(f.Name)) return true }) } else { n, err := protocol.DeviceIDFromString(*device) if err != nil { log.Fatal(err) } log.Printf("*** Have index for folder %q device %q", *folder, n) fs.WithHaveTruncated(n, func(fi protocol.FileIntf) bool { f := fi.(protocol.FileInfoTruncated) fmt.Println(f) return true }) } }
func init() { device1, _ = protocol.DeviceIDFromString("AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ") device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY") device3, _ = protocol.DeviceIDFromString("LGFPDIT-7SKNNJL-VJZA4FC-7QNCRKA-CE753K7-2BW5QDK-2FOZ7FR-FEP57QJ") device4, _ = protocol.DeviceIDFromString("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2") }
func init() { device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR") device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY") }
func init() { remoteDevice0, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR") remoteDevice1, _ = protocol.DeviceIDFromString("I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU") }