Skip to content

Commit

Permalink
clean code web on chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Jan 8, 2024
1 parent b67dd38 commit 65f7fc7
Show file tree
Hide file tree
Showing 59 changed files with 30 additions and 2,542 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ If you want to contribute to the installers, please refer to the [MassaStation I

### Developer guide

If you want to change the network to which Massa Station will connect and the DNS contract address you can change the file
If you want to change the network to which Massa Station will connect you can change the file
`int/config/config_network.yaml` and compile Massa Station again with `task build`.
10 changes: 3 additions & 7 deletions api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"net/http"

"github.com/massalabs/station/api/interceptor"
"github.com/massalabs/station/int/config"
"github.com/massalabs/station/int/configuration"
"github.com/massalabs/station/pkg/logger"
"github.com/massalabs/station/pkg/onchain/website"
"github.com/massalabs/station/pkg/plugin"
)

Expand All @@ -16,10 +14,9 @@ var configDir string

// TopMiddleware is called by go-swagger framework before its endpoints.
// current defined interceptor are:
// - MassaTLDInterceptor to handle *.massa websites
// - Plugin interceptor to handle call to registered plugins
// - Default resource interceptor to handle browser call (needed for mobile?) and web resources not yet pluginized.
func TopMiddleware(handler http.Handler, cfg config.NetworkInfos) http.Handler {
func TopMiddleware(handler http.Handler) http.Handler {
//nolint:varnamelen
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger.Infof("[%s %s]", r.Method, r.URL.Path)
Expand All @@ -34,8 +31,7 @@ func TopMiddleware(handler http.Handler, cfg config.NetworkInfos) http.Handler {

// Goes through all local interceptors.
req := RedirectToDefaultResourceInterceptor(
plugin.Interceptor(
website.MassaTLDInterceptor(&interceptor.Interceptor{Writer: w, Request: r}, cfg, configDir))) //nolint:contextcheck
plugin.Interceptor(&interceptor.Interceptor{Writer: w, Request: r}))
// if the request was not handled by any interceptor, let the swagger API takes care of it.
if req != nil {
handler.ServeHTTP(w, r)
Expand All @@ -62,7 +58,7 @@ func RedirectToDefaultResourceInterceptor(req *interceptor.Interceptor) *interce
return nil
}

redirectPaths := []string{"/web", "/home", "/search", "/websiteUploader", "/store"}
redirectPaths := []string{"/web", "/home", "/search", "/store"}

for _, path := range redirectPaths {
if req.Request.URL.Path == path || req.Request.URL.Path == path+"/" {
Expand Down
13 changes: 6 additions & 7 deletions api/swagger/server/restapi/configure_massastation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/massalabs/station/api"
"github.com/massalabs/station/api/swagger/server/restapi/operations"
"github.com/massalabs/station/int/config"
"github.com/massalabs/station/int/configuration"
"github.com/massalabs/station/int/sni"
"github.com/massalabs/station/pkg/logger"
Expand All @@ -30,13 +29,13 @@ func configureAPI(api *operations.MassastationAPI) http.Handler {
return nil
}

func (s *Server) ConfigureMassaStationAPI(config config.NetworkInfos, shutdown chan struct{}) {
func (s *Server) ConfigureMassaStationAPI(shutdown chan struct{}) {
if s.api != nil {
s.handler = configureMassaStationAPI(s.api, config, shutdown)
s.handler = configureMassaStationAPI(s.api, shutdown)
}
}

func configureMassaStationAPI(api *operations.MassastationAPI, config config.NetworkInfos, shutdown chan struct{}) http.Handler {
func configureMassaStationAPI(api *operations.MassastationAPI, shutdown chan struct{}) http.Handler {
// configure the api here
api.ServeError = errors.ServeError

Expand Down Expand Up @@ -84,7 +83,7 @@ func configureMassaStationAPI(api *operations.MassastationAPI, config config.Net
logger.Infof(msg, args...)
}

return setupGlobalMiddleware(api.Serve(setupMiddlewares), config)
return setupGlobalMiddleware(api.Serve(setupMiddlewares))
}

// The TLS configuration before HTTPS server starts.
Expand Down Expand Up @@ -124,8 +123,8 @@ func setupMiddlewares(handler http.Handler) http.Handler {
// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json
// document.
// So this is a good place to plug in a panic handling middleware, logging and metrics.
func setupGlobalMiddleware(handler http.Handler, config config.NetworkInfos) http.Handler {
func setupGlobalMiddleware(handler http.Handler) http.Handler {
handleCORS := cors.Default().Handler

return api.TopMiddleware(handleCORS(handler), config)
return api.TopMiddleware(handleCORS(handler))
}
234 changes: 0 additions & 234 deletions api/swagger/server/restapi/resource/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ schemes:
- https
swagger: "2.0"
paths:
/all/domains:
get:
description: Returns all domains registered in the blockchain network MassaServer is connected to.
operationId: allDomainsGetter
produces:
- application/json
responses:
"200":
description: All domains returned.
schema:
type: array
items:
$ref: "#/definitions/Registry"
"400":
description: Bad request.
schema:
$ref: "#/definitions/Error"
"500":
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/cmd/executeFunction:
post:
description: Calls the given function from the given smart contract.
Expand Down Expand Up @@ -337,33 +316,6 @@ paths:
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/my/domains/{nickname}:
get:
description: Retrieves the list of domains owned by the given wallet.
operationId: myDomainsGetter
parameters:
- in: path
name: nickname
type: string
required : true
description: Wallet's short name.
produces:
- application/json
responses:
"200":
description: Domains returned. May be empty.
schema:
type: array
items:
$ref: "#/definitions/Websites"
"400":
description: Bad request.
schema:
$ref: "#/definitions/Error"
"500":
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/network:
get:
description: Retrieves the network configuration.
Expand Down Expand Up @@ -752,155 +704,6 @@ paths:
responses:
"200":
description: Dumb response. All content and HTTP code are possible for this endpoint.
/websiteUploader/prepare:
put:
summary: Deploys the given website on the blockchain.
description: The given URL will first be added to the DNS if available and then the website will be deployed.
operationId: websiteUploaderPrepare
consumes:
- multipart/form-data
parameters:
- in: formData
name: url
type: string
pattern: "^[a-z0-9_\\-]{3,50}$"
required: true
x-nullable: false
description: URL using lowercase letters (a-z), numbers (0-9), hyphen (-), and underscore (_).
- in: formData
name: description
type: string
maxLength: 280
required: true
x-nullable: false
description: Website description with a maximum length of 280 characters.
- in: formData
name: nickname
type: string
required: true
x-nullable: false
description: Name of the Wallet in which the website will be deployed.
- in: formData
name: zipfile
type: file
required: true
x-nullable: false
description: Website contents in a ZIP file.

produces:
- application/json
responses:
"200":
description: New website created.
schema:
$ref: "#/definitions/Websites"
"400":
description: Bad request.
schema:
$ref: "#/definitions/Error"
"422":
description: Unprocessable Entity - syntax is correct, but the server was unable to process the contained instructions.
schema:
$ref: "#/definitions/Error"
"500":
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/websiteUploader/upload:
post:
summary: Uploads the given website on the blockchain.
description: The website must have been deployed before using the prepare endpoint. This endpoint is usually used to edit an existing website.
operationId: websiteUploaderUpload
consumes:
- multipart/form-data
parameters:
- in: formData
name: address
type: string
required: true
x-nullable: false
description: Address where to deploy website. The account must have been prepare to receive a website.
- in: formData
name: nickname
type: string
required: true
x-nullable: false
description: Wallet's nickname to be used for receiving the website
- in: formData
name: zipfile
type: file
required: true
x-nullable: false
description: Website contents in a ZIP file.
produces:
- application/json
responses:
"200":
description: Website's chunk deployed.
schema:
$ref: "#/definitions/Websites"
"400":
description: Bad request.
schema:
$ref: "#/definitions/Error"
"422":
description: Unprocessable Entity - syntax is correct, but the server was unable to process the contained instructions.
schema:
$ref: "#/definitions/Error"
"500":
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/websiteUploader/uploadMissingChunks:
post:
description: Re-upload missing chunks of a website on the blockchain. This allows to fix a website that has been partially uploaded as a lower cost than re-uploading the whole website.
operationId: websiteUploadMissingChunks
consumes:
- multipart/form-data
parameters:
- in: formData
name: address
type: string
required: true
x-nullable: false
description: Address where to deploy website. The account must have been prepare to receive a website.
- in: formData
name: nickname
type: string
required: true
x-nullable: false
description: Wallet's nickname to be used for receiving the website
- in: formData
name: zipfile
type: file
required: true
x-nullable: false
description: Website contents in a ZIP file.
- in: formData
name: missedChunks
type: string
required: true
x-nullable: false
description: Website missing chunks
produces:
- application/json
responses:
"200":
description: Website's chunk deployed.
schema:
$ref: "#/definitions/Websites"
"400":
description: Bad request.
schema:
$ref: "#/definitions/Error"
"422":
description: Unprocessable Entity - syntax is correct, but the server was unable to process the contained instructions.
schema:
$ref: "#/definitions/Error"
"500":
description: Internal Server Error - The server has encountered a situation it does not know how to handle.
schema:
$ref: "#/definitions/Error"
/version:
get:
description: "Get current massastation version"
Expand Down Expand Up @@ -941,24 +744,6 @@ definitions:
description: error message.
type: string
x-nullable: false
Websites:
type: object
description: Websites object (V0).
properties:
name:
description: Website's name.
type: string
description:
description: Website's description.
type: string
address:
description: Website's address.
type: string
brokenChunks:
description: Array of empty chunks if website contains preventing the website to load.
type: array
items:
type: string
Events:
type: object
description: Events object (V0)
Expand All @@ -984,23 +769,6 @@ definitions:
required:
- currentNetwork
- availableNetworks
Registry:
type: object
description: Registry object (V0).
properties:
name:
description: Website's name.
type: string
address:
description: Website's address.
type: string
description:
description: Website's description.
type: string
favicon:
description: Website's favicon host and path
example: flappy.massa/favicon.ico
type: string
PluginStoreItem:
type: object
description: Plugin item from store.
Expand Down Expand Up @@ -1049,8 +817,6 @@ definitions:
enum: ["testnet", "labnet", "localhost", "buildnet"]
url:
type: string
dns:
type: string
chainId:
type: integer
required:
Expand Down
Loading

0 comments on commit 65f7fc7

Please sign in to comment.