From 83de5ad620c7f3dca274af44d53ef1993d2c232e Mon Sep 17 00:00:00 2001 From: Mickael KERJEAN Date: Thu, 20 Dec 2018 09:02:30 +1100 Subject: [PATCH] fix (build): broken build --- .drone.yml | 2 +- client/helpers/form.js | 38 ++++++++++++++++++ client/helpers/index.js | 2 +- client/model/config.js | 2 +- client/pages/adminpage/dashboard.js | 39 +------------------ client/pages/connectpage/form.js | 19 ++++++--- docker/prod/Dockerfile | 9 +++-- server/main.go | 4 +- server/model/files_test.go | 1 - .../{image_heavy => plg_image_heavy}/index.go | 2 +- .../{image_light => plg_image_light}/build.sh | 0 .../{image_light => plg_image_light}/index.go | 4 +- .../lib/raw.c | 0 .../lib/raw.go | 0 .../lib/raw.h | 0 .../lib/resizer.c | 0 .../lib/resizer.go | 0 .../lib/resizer.h | 0 18 files changed, 66 insertions(+), 56 deletions(-) rename server/plugin/{image_heavy => plg_image_heavy}/index.go (96%) rename server/plugin/{image_light => plg_image_light}/build.sh (100%) rename server/plugin/{image_light => plg_image_light}/index.go (96%) rename server/plugin/{image_light => plg_image_light}/lib/raw.c (100%) rename server/plugin/{image_light => plg_image_light}/lib/raw.go (100%) rename server/plugin/{image_light => plg_image_light}/lib/raw.h (100%) rename server/plugin/{image_light => plg_image_light}/lib/resizer.c (100%) rename server/plugin/{image_light => plg_image_light}/lib/resizer.go (100%) rename server/plugin/{image_light => plg_image_light}/lib/resizer.h (100%) diff --git a/.drone.yml b/.drone.yml index 7daabfed..913a311a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ steps: CGO_LDFLAGS_ALLOW: '-fopenmp' commands: - cd server - - rm -rf plugin + - rm -rf plugin/plg_* - go get -t ./... - go build - go test -v ./... diff --git a/client/helpers/form.js b/client/helpers/form.js index 90d169e4..a1010f88 100644 --- a/client/helpers/form.js +++ b/client/helpers/form.js @@ -14,3 +14,41 @@ export const FormObjToJSON = function(o, fn){ }); return obj }; + + +export function createFormBackend(backend_available, backend_data){ + if(!backend_available) return {}; + + let template = JSON.parse(JSON.stringify(backend_available[backend_data.type])); + + for(let key in backend_data){ + if(key in template){ + template[key].value = backend_data[key]; + template[key].enabled = true; + } else { + // create a form object if data isn't available in the template + let obj = {}; + obj[key] = { + label: key, + type: "text", + value: null, + default: backend_data[key] + }; + template = Object.assign(obj, template); + } + + if(key === "label"){ + template[key].placeholder = "Name as shown on the login screen."; + template[key].value = backend_data[key]; + template[key].enabled = true; + } else if(key === "type"){ + template[key].enabled = true; + } else if(key === "advanced"){ + template[key].enabled = true; + } + } + + let obj = {}; + obj[backend_data.type] = template; + return obj; +} diff --git a/client/helpers/index.js b/client/helpers/index.js index 2f4febc5..4d8a8976 100644 --- a/client/helpers/index.js +++ b/client/helpers/index.js @@ -14,5 +14,5 @@ export { gid, randomString } from './random'; export { leftPad, copyToClipboard } from './common'; export { getMimeType } from './mimetype'; export { settings_get, settings_put } from './settings'; -export { FormObjToJSON } from './form'; +export { FormObjToJSON, createFormBackend } from './form'; export { format } from './text'; diff --git a/client/model/config.js b/client/model/config.js index d31581ef..4ef1ae3f 100644 --- a/client/model/config.js +++ b/client/model/config.js @@ -52,7 +52,7 @@ class BackendModel { constructor(){} all(){ - return http_get("/admin/api/backend").then((r) => r.result); + return http_get("/api/backend").then((r) => r.result); } } diff --git a/client/pages/adminpage/dashboard.js b/client/pages/adminpage/dashboard.js index b62b7fd5..ec73ab96 100644 --- a/client/pages/adminpage/dashboard.js +++ b/client/pages/adminpage/dashboard.js @@ -1,7 +1,7 @@ import React from 'react'; import { FormBuilder, Icon, Input } from "../../components/"; import { Backend, Config } from "../../model/"; -import { FormObjToJSON, notify, format } from "../../helpers/"; +import { FormObjToJSON, notify, format, createFormBackend } from "../../helpers/"; import "./dashboard.scss"; @@ -158,40 +158,3 @@ export class DashboardPage extends React.Component { ); } } - - - -function createFormBackend(backend_available, backend_data){ - let template = JSON.parse(JSON.stringify(backend_available[backend_data.type])); - - for(let key in backend_data){ - if(key in template){ - template[key].value = backend_data[key]; - template[key].enabled = true; - } else { - // create a form object if data isn't available in the template - let obj = {}; - obj[key] = { - label: key, - type: "text", - value: null, - default: backend_data[key] - }; - template = Object.assign(obj, template); - } - - if(key === "label"){ - template[key].placeholder = "Name as shown on the login screen."; - template[key].value = backend_data[key]; - template[key].enabled = true; - } else if(key === "type"){ - template[key].enabled = true; - } else if(key === "advanced"){ - template[key].enabled = true; - } - } - - let obj = {}; - obj[backend_data.type] = template; - return obj; -} diff --git a/client/pages/connectpage/form.js b/client/pages/connectpage/form.js index a791f08f..15ff4468 100644 --- a/client/pages/connectpage/form.js +++ b/client/pages/connectpage/form.js @@ -1,7 +1,7 @@ import React from "react"; -import { Container, Card, NgIf, Input, Button, Textarea, Loader, Notification, Prompt } from "../../components/"; -import { invalidate, encrypt, decrypt, gid, settings_get, settings_put } from "../../helpers/"; -import { Session } from "../../model/"; +import { Container, Card, NgIf, Input, Button, Textarea, FormBuilder } from "../../components/"; +import { gid, settings_get, settings_put, createFormBackend } from "../../helpers/"; +import { Session, Backend } from "../../model/"; import "./form.scss"; import img_drive from "../../assets/img/google-drive.png"; import img_dropbox from "../../assets/img/dropbox.png"; @@ -10,19 +10,26 @@ export class Form extends React.Component { constructor(props){ super(props); this.state = { - select: CONFIG["connections"].length > 2 ? 2 : 0, - backends: JSON.parse(JSON.stringify(CONFIG["connections"])), + select: window.CONFIG["connections"].length > 2 ? 2 : 0, + backends: JSON.parse(JSON.stringify(window.CONFIG["connections"])).map((backend) => { + return backend; + }), dummy: null }; const select = settings_get("login_tab"); - if(select !== null && select < CONFIG["connections"].length){ this.state.select = select; } + if(select !== null && select < window.CONFIG["connections"].length){ this.state.select = select; } this.rerender = this.rerender.bind(this); } componentDidMount(){ window.addEventListener("resize", this.rerender); this.publishState(this.props); + Backend.all().then((b) => { + this.setState({ + backend_available: b + }); + }); } componentWillUnmount(){ diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index c0d9d62b..62518525 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -7,8 +7,10 @@ ENV CGO_LDFLAGS_ALLOW='-fopenmp' RUN mkdir -p $GOPATH/src/github.com/mickael-kerjean/ && \ ################# # Dependencies - apk --no-cache --virtual .build-deps add make gcc g++ curl nodejs git go npm && \ + apk --no-cache --virtual .build-deps add make gcc g++ curl nodejs git npm && \ + apk --no-cache --virtual .go add go --repository http://dl-3.alpinelinux.org/alpine/edge/community && \ mkdir /tmp/deps && \ + cd /tmp/deps && \ # libvips ####### cd /tmp/deps && \ curl -L -X GET https://github.com/libvips/libvips/releases/download/v8.7.0/vips-8.7.0.tar.gz > libvips.tar.gz && \ @@ -45,7 +47,7 @@ RUN mkdir -p $GOPATH/src/github.com/mickael-kerjean/ && \ ################# # Compile Plugins mkdir -p ./dist/data/plugin && \ - go build -buildmode=plugin -o ./dist/data/plugin/image.so server/plugin/image_light/index.go && \ + go build -buildmode=plugin -o ./dist/data/plugin/image.so server/plugin/plg_image_light/index.go && \ ################# # Finalise the build cd $GOPATH/src/github.com/mickael-kerjean/nuage/ && \ @@ -54,7 +56,8 @@ RUN mkdir -p $GOPATH/src/github.com/mickael-kerjean/ && \ cd /app && \ rm -rf $GOPATH && \ rm -rf /tmp/* && \ - apk del .build-deps + apk del .build-deps && \ + apk del .go EXPOSE 8334 VOLUME ["/app/data/config/"] diff --git a/server/main.go b/server/main.go index c7a4b959..c7a5fb6b 100644 --- a/server/main.go +++ b/server/main.go @@ -67,14 +67,14 @@ func Init(a *App) { admin := r.PathPrefix("/admin/api").Subrouter() admin.HandleFunc("/session", CtxInjector(AdminSessionGet, *a)).Methods("GET") admin.HandleFunc("/session", CtxInjector(AdminSessionAuthenticate, *a)).Methods("POST") - admin.HandleFunc("/backend", CtxInjector(AdminBackend, *a)).Methods("GET") admin.HandleFunc("/plugin", CtxInjector(AdminOnly(FetchPluginsHandler), *a)).Methods("GET") admin.HandleFunc("/log", CtxInjector(AdminOnly(FetchLogHandler), *a)).Methods("GET") admin.HandleFunc("/config", CtxInjector(AdminOnly(PrivateConfigHandler), *a)).Methods("GET") admin.HandleFunc("/config", CtxInjector(AdminOnly(PrivateConfigUpdateHandler), *a)).Methods("POST") // APP - r.HandleFunc("/api/config", CtxInjector(PublicConfigHandler, *a)).Methods("GET") + r.HandleFunc("/api/config", CtxInjector(PublicConfigHandler, *a)).Methods("GET") + r.HandleFunc("/api/backend", CtxInjector(AdminBackend, *a)).Methods("GET") r.HandleFunc("/favicon.ico", func(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/assets/logo/favicon.ico", http.StatusPermanentRedirect) }) diff --git a/server/model/files_test.go b/server/model/files_test.go index 43b435ba..1e3c34d7 100644 --- a/server/model/files_test.go +++ b/server/model/files_test.go @@ -11,7 +11,6 @@ var app *App func init() { app = &App{} - app.Config = &Config{} } // func TestWebdav(t *testing.T) { diff --git a/server/plugin/image_heavy/index.go b/server/plugin/plg_image_heavy/index.go similarity index 96% rename from server/plugin/image_heavy/index.go rename to server/plugin/plg_image_heavy/index.go index 9321d928..95c82714 100644 --- a/server/plugin/image_heavy/index.go +++ b/server/plugin/plg_image_heavy/index.go @@ -9,7 +9,7 @@ import ( "net/http" ) -func Init(config *Config) { +func Init(config *Configuration) { plugin_enable := config.Get("transcoder.image.enable").Default(true).Bool() plugin_thumbsize := uint(config.Get("transcoder.image.thumbnail_size").Default(300).Int()) diff --git a/server/plugin/image_light/build.sh b/server/plugin/plg_image_light/build.sh similarity index 100% rename from server/plugin/image_light/build.sh rename to server/plugin/plg_image_light/build.sh diff --git a/server/plugin/image_light/index.go b/server/plugin/plg_image_light/index.go similarity index 96% rename from server/plugin/image_light/index.go rename to server/plugin/plg_image_light/index.go index d3bc504e..a9bcd420 100644 --- a/server/plugin/image_light/index.go +++ b/server/plugin/plg_image_light/index.go @@ -2,7 +2,7 @@ package main import ( . "github.com/mickael-kerjean/nuage/server/common" - "github.com/mickael-kerjean/nuage/server/plugin/image_light/lib" + "github.com/mickael-kerjean/nuage/server/plugin/plg_image_light/lib" "io" "net/http" "os" @@ -15,7 +15,7 @@ const ( ImageCachePath = "data/cache/image/" ) -func Init(conf *Config) { +func Init(conf *Configuration) { plugin_enable := conf.Get("transcoder.image.enable").Default(true).Bool() cachePath := filepath.Join(GetCurrentDir(), ImageCachePath) diff --git a/server/plugin/image_light/lib/raw.c b/server/plugin/plg_image_light/lib/raw.c similarity index 100% rename from server/plugin/image_light/lib/raw.c rename to server/plugin/plg_image_light/lib/raw.c diff --git a/server/plugin/image_light/lib/raw.go b/server/plugin/plg_image_light/lib/raw.go similarity index 100% rename from server/plugin/image_light/lib/raw.go rename to server/plugin/plg_image_light/lib/raw.go diff --git a/server/plugin/image_light/lib/raw.h b/server/plugin/plg_image_light/lib/raw.h similarity index 100% rename from server/plugin/image_light/lib/raw.h rename to server/plugin/plg_image_light/lib/raw.h diff --git a/server/plugin/image_light/lib/resizer.c b/server/plugin/plg_image_light/lib/resizer.c similarity index 100% rename from server/plugin/image_light/lib/resizer.c rename to server/plugin/plg_image_light/lib/resizer.c diff --git a/server/plugin/image_light/lib/resizer.go b/server/plugin/plg_image_light/lib/resizer.go similarity index 100% rename from server/plugin/image_light/lib/resizer.go rename to server/plugin/plg_image_light/lib/resizer.go diff --git a/server/plugin/image_light/lib/resizer.h b/server/plugin/plg_image_light/lib/resizer.h similarity index 100% rename from server/plugin/image_light/lib/resizer.h rename to server/plugin/plg_image_light/lib/resizer.h