Compare commits
No commits in common. "47472eb1c61f460ea3d9912b2974eb6c7a92f55f" and "d018c0c2ba104d6007774199400491fe9e299c83" have entirely different histories.
47472eb1c6
...
d018c0c2ba
|
@ -14,8 +14,6 @@ tags:
|
|||
description: API for serving data
|
||||
- name: System API
|
||||
description: API for serving system data
|
||||
- name: Internal API
|
||||
description: API for microservices. Shouldn't be accessible via WAN
|
||||
|
||||
paths:
|
||||
/{id}:
|
||||
|
@ -47,47 +45,4 @@ paths:
|
|||
schema:
|
||||
type: boolean
|
||||
example: true
|
||||
/internal/check_resource:
|
||||
post:
|
||||
summary: Check if a resource(s) exist
|
||||
description: |-
|
||||
This method takes an array of resources and reports which ones exist.
|
||||
|
||||
See responses for more info.
|
||||
tags:
|
||||
- Internal API
|
||||
requestBody:
|
||||
description: |-
|
||||
An array of strings, where each string is a resource ID
|
||||
|
||||
Let's assume that we want to check if two resources exist: `dev.blek.file.logo` and `org.nonexistant.resource`.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example:
|
||||
- dev.blek.file.logo
|
||||
- org.nonexistant.resource
|
||||
responses:
|
||||
200:
|
||||
description: |-
|
||||
As in the request body example, let's assume that this method checked if these two resources exist:
|
||||
- `dev.blek.file.logo`
|
||||
- `org.nonexistant.resource`
|
||||
|
||||
As we can see, this returned only `dev.blek.file.logo` because its the only resource of the provided ones that exist.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
|
||||
example:
|
||||
dev.blek.file.logo:
|
||||
type: image/png
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
import (
|
||||
|
@ -21,9 +20,6 @@ type Resource struct {
|
|||
Proxied bool `toml:"proxied",default:false`
|
||||
Mime string `toml:"mime"`
|
||||
}
|
||||
type CheckResourceType struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
func (self Resource) Get() ([]byte, error) {
|
||||
return ioutil.ReadFile(self.Url[7:])
|
||||
}
|
||||
|
@ -119,34 +115,6 @@ func main() {
|
|||
}
|
||||
return c.Next()
|
||||
})
|
||||
app.Post("/internal/check_resource", func (c *fiber.Ctx) error {
|
||||
|
||||
resources := new([]string)
|
||||
err := json.Unmarshal(c.Body(), &resources)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return c.Send([]byte("{ \"error\": \"500\"}"))
|
||||
}
|
||||
|
||||
resources_exist := make(map[string]CheckResourceType)
|
||||
|
||||
for _, resource := range *resources {
|
||||
if val, ok := conf.Resource[resource]; ok {
|
||||
resources_exist[resource] = CheckResourceType {
|
||||
Type: val.Mime,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(resources_exist)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return c.Send([]byte("{ \"error\": \"500\"}"))
|
||||
}
|
||||
|
||||
return c.Send([]byte(marshaled))
|
||||
})
|
||||
|
||||
app.Get("/:id", func (c *fiber.Ctx) error {
|
||||
res, exists := conf.Resource[c.Params("id")]
|
||||
|
|
Loading…
Reference in New Issue