migration: migrate NodeJS code base to Golang

This commit is contained in:
Mickael Kerjean
2018-07-30 13:34:44 +10:00
parent c5f2839fd7
commit 04c97e34fb
68 changed files with 3837 additions and 2217 deletions
Binary file not shown.
+9 -8
View File
@@ -49,7 +49,7 @@ Data.prototype.get = function(type, path){
};
query.onerror = error;
});
});
}).catch(() => Promise.resolve(null))
}
Data.prototype.update = function(type, path, fn, exact = true){
@@ -73,7 +73,7 @@ Data.prototype.update = function(type, path, fn, exact = true){
cursor.continue();
};
});
});
}).catch(() => Promise.resolve(null))
}
@@ -93,7 +93,7 @@ Data.prototype.upsert = function(type, path, fn){
};
query.onerror = error;
});
});
}).catch(() => Promise.resolve(null))
}
Data.prototype.add = function(type, path, data){
@@ -107,7 +107,7 @@ Data.prototype.add = function(type, path, data){
request.onsuccess = () => done(data);
request.onerror = (e) => error(e);
});
});
}).catch(() => Promise.resolve(null))
}
Data.prototype.remove = function(type, path, exact = true){
@@ -139,7 +139,7 @@ Data.prototype.remove = function(type, path, exact = true){
};
});
}
});
}).catch(() => Promise.resolve(null))
}
Data.prototype.fetchAll = function(fn, type = this.FILE_PATH){
@@ -156,11 +156,13 @@ Data.prototype.fetchAll = function(fn, type = this.FILE_PATH){
cursor.continue();
};
});
});
}).catch(() => Promise.resolve(null))
}
Data.prototype.destroy = function(){
this.db.then((db) => db.close())
this.db
.then((db) => db.close())
.catch(() => {})
clearTimeout(this.intervalId);
window.indexedDB.deleteDatabase('nuage');
this._init();
@@ -168,4 +170,3 @@ Data.prototype.destroy = function(){
export const cache = new Data();
window._cache = cache;
+1 -2
View File
@@ -1,9 +1,8 @@
import Path from 'path';
import db from '../../server/common/mimetype.json';
export function getMimeType(file){
let ext = Path.extname(file).replace(/^\./, '').toLowerCase();
let mime = db[ext];
let mime = CONFIG.mime[ext];
if(mime){
return mime;
}else{
-6
View File
@@ -24,14 +24,8 @@
<link rel="icon" type="image/png" sizes="96x96" href="/assets/logo/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/logo/favicon-16x16.png">
<link rel="icon" href="/assets/logo/favicon.ico" type="image/x-icon" />
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<script src="/api/config"></script>
<!--[if IE]>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
<![endif]-->
<meta name="msapplication-TileColor" content="#f2f2f2">
<meta name="msapplication-TileImage" content="/assets/logo/ms-icon-144x144.png">
<meta name="theme-color" content="#f2f2f2">
+3
View File
@@ -389,6 +389,9 @@ const S3Form = formHelper(function(props){
<NgIf cond={props.should_appear("path")}>
<Input value={props.values["path"] || ""} onChange={(e) => props.onChange("path", e.target.value)} type={props.input_type("path")} name="path" placeholder="Path" autoComplete="new-password" />
</NgIf>
<NgIf cond={props.should_appear("region")}>
<Input value={props.values["region"] || ""} onChange={(e) => props.onChange("region", e.target.value)} type={props.input_type("region")} name="region" placeholder="Region" autoComplete="new-password" />
</NgIf>
<NgIf cond={props.should_appear("endpoint")}>
<Input value={props.values["endpoint"] || ""} onChange={(e) => props.onChange("endpoint", e.target.value)} type={props.input_type("endpoint")} name="endpoint" placeholder="Endpoint" autoComplete="new-password" />
</NgIf>
+1 -1
View File
@@ -123,7 +123,7 @@ export class ExistingThing extends React.Component {
const type = getMimeType(_path).split("/")[0];
if(type === "image"){
Files.url(_path).then((url) => {
this.setState({preview: url+"&size=250"});
this.setState({preview: url+"&thumbnail=true"});
});
}
}
+1 -1
View File
@@ -262,7 +262,7 @@ class Img extends React.Component{
render(){
const image_url = (url, size) => {
return url+"&meta=true&size="+parseInt(window.innerWidth*size);
return url+"&size="+parseInt(window.innerWidth*size);
};
if(!this.props.src) return null;
+5
View File
@@ -0,0 +1,5 @@
describe('Helpers::event', () => {
it('test', () => {
});
});
+20
View File
@@ -0,0 +1,20 @@
// import assert from 'assert';
// import { encrypt, decrypt } from '../client/helpers/';
// describe("Helper::crypto", function() {
// it("can encrypt", function() {
// const key = "SUPER_KEY";
// const obj = {a: 3, b:4}
// const encrypted_obj = encrypt(obj, key);
// assert.ok(encrypted_obj);
// assert.notEqual(obj, encrypted_obj);
// });
// it("can decrypt", function() {
// const key = "SUPER_KEY";
// const obj = {a: 3, b:4}
// const encrypted_obj = encrypt(obj,key);
// const decrypted_obj = decrypt(encrypted_obj, key);
// assert.equal(JSON.stringify(obj), JSON.stringify(decrypted_obj));
// });
// });
+44
View File
@@ -0,0 +1,44 @@
// import assert from 'assert';
// import { event } from '../client/helpers/';
// describe("Helper::event", function() {
// afterEach(function(){
// event.fns = [];
// });
// it("can register", function() {
// assert.equal(0, event.fns.length);
// event.subscribe("event::test", function(){});
// assert.equal(1, event.fns.length);
// });
// it("can unregister", function() {
// assert.equal(0, event.fns.length);
// event.subscribe("event::test", function(){});
// assert.equal(1, event.fns.length);
// event.unsubscribe("event::test");
// assert.equal(0, event.fns.length);
// });
// it("can emit", function(done){
// event.subscribe('event::test', function(){
// done();
// });
// event.emit("event::test")
// });
// it("can emit multiple times", function(done){
// let count = 0;
// event.subscribe('event::test', function(){
// count += 1;
// if(count === 3){
// done();
// }else{
// assert.equal(true, count < 3);
// }
// });
// event.emit("event::test");
// event.emit("event::test");
// event.emit("event::test");
// });
// });
+24
View File
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<!-- Helpers -->
<!--<script type="module" src="/client/helpers/events.js"></script>-->
<script type="module" src="../client/helpers/crypto.js"></script>
<!-- load your test files here -->
<script>
mocha.run();
</script>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/Spec\.js$/.test(file)) {
tests.push(file);
}
}
}
requirejs.config({
baseUrl: '/base/src',
paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore',
},
shim: {
'underscore': {
exports: '_'
}
},
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
});
+1 -1
View File
@@ -1,4 +1,4 @@
const CACHE_NAME = 'v1.0';
const CACHE_NAME = 'v0.3';
const DELAY_BEFORE_SENDING_CACHE = 2000;
/*