Fixed body and header issues with app creator

This commit is contained in:
frikky
2020-06-01 10:05:20 +02:00
parent 8cfbb39386
commit 4e10981db5
4 changed files with 109 additions and 89 deletions
+21 -13
View File
@@ -2112,7 +2112,6 @@ func SetSession(ctx context.Context, Userdata User, value string) error {
func setOpenApiDatastore(ctx context.Context, id string, data ParsedOpenApi) error {
k := datastore.NameKey("openapi3", id, nil)
if _, err := dbclient.Put(ctx, k, &data); err != nil {
log.Println(err)
return err
}
@@ -5075,6 +5074,8 @@ func getOpenapi(resp http.ResponseWriter, request *http.Request) {
return
}
log.Printf("API LENGTH GET: %d, ID: %s", len(parsedApi.Body), id)
parsedApi.Success = true
data, err := json.Marshal(parsedApi)
if err != nil {
@@ -5505,13 +5506,6 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
// Test = client side with fetch?
ctx := context.Background()
//client, err := storage.NewClient(ctx)
//if err != nil {
// log.Printf("Failed to create client (storage): %v", err)
// resp.WriteHeader(401)
// resp.Write([]byte(`{"success": false, "reason": "Failed creating client"}`))
// return
//}
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(body)
if err != nil {
@@ -5542,6 +5536,9 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
return
}
log.Printf("PATHS: %#v", swagger.Paths["/comments/put"])
log.Printf("Functions: %d", len(swagger.Paths))
log.Printf("Actions: %d", len(api.Actions))
api.Owner = user.Id
err = dumpApi(basePath, api)
@@ -5680,24 +5677,35 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
return
}
log.Printf("DO I REACH HERE WHEN SAVING?")
parsed := ParsedOpenApi{
ID: api.ID,
ID: newmd5,
Body: string(body),
}
setOpenApiDatastore(ctx, api.ID, parsed)
err = increaseStatisticsField(ctx, "total_apps_created", api.ID, 1)
log.Printf("API LENGTH: %d, ID: %s", len(parsed.Body), newmd5)
// FIXME: Might cause versioning issues if we re-use the same!!
// FIXME: Need a way to track different versions of the same app properly.
// Hint: Save API.id somewhere, and use newmd5 to save latest version
err = setOpenApiDatastore(ctx, newmd5, parsed)
if err != nil {
log.Printf("Failed saving to datastore: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "%"}`, err)))
}
err = increaseStatisticsField(ctx, "total_apps_created", newmd5, 1)
if err != nil {
log.Printf("Failed to increase success execution stats: %s", err)
}
err = increaseStatisticsField(ctx, "openapi_apps_created", api.ID, 1)
err = increaseStatisticsField(ctx, "openapi_apps_created", newmd5, 1)
if err != nil {
log.Printf("Failed to increase success execution stats: %s", err)
}
resp.WriteHeader(200)
resp.Write([]byte(`{"success": true}`))
resp.Write([]byte(fmt.Sprintf(`{"success": true, "id": "%s"}`, api.ID)))
}
func healthCheckHandler(resp http.ResponseWriter, request *http.Request) {