Merge branch 'master' of ssh.dev.azure.com:v3/HackKu/HackKu%202020/backend
This commit is contained in:
commit
8714ab79f1
BIN
app/assets/favicon-16x16.png
Normal file
BIN
app/assets/favicon-16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 639 B |
BIN
app/assets/favicon-32x32.png
Normal file
BIN
app/assets/favicon-32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 15 KiB |
@ -11,7 +11,7 @@ const path = require('path');
|
|||||||
*/
|
*/
|
||||||
class Export extends Controller {
|
class Export extends Controller {
|
||||||
static get services() {
|
static get services() {
|
||||||
return [...super.services, 'models']
|
return [...super.services, 'models', 'app']
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Serve the main page.
|
* Serve the main page.
|
||||||
@ -40,11 +40,12 @@ class Export extends Controller {
|
|||||||
const temp_dir = path.resolve(os.tmpdir(), uuid())
|
const temp_dir = path.resolve(os.tmpdir(), uuid())
|
||||||
|
|
||||||
await fs.mkdir(temp_dir)
|
await fs.mkdir(temp_dir)
|
||||||
this._markdown_recurse(page0, temp_dir)
|
await this._markdown_recurse(page0, temp_dir)
|
||||||
|
|
||||||
/* Archive directory */
|
/* Archive directory */
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
exec('zip -r ' + path.resolve(temp_dir, 'archive.zip') + ' ' + path.resolve(temp_dir), (error) => {
|
console.log('zip -9jpr ' + path.resolve(temp_dir, '../archive.zip') + ' ' + path.resolve(temp_dir) + '/')
|
||||||
|
exec('cd ' + path.resolve(temp_dir) + '; zip -r archive.zip *', (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`exec error: ${error}`);
|
console.error(`exec error: ${error}`);
|
||||||
return res.error(500);
|
return res.error(500);
|
||||||
@ -56,16 +57,17 @@ class Export extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _markdown_recurse(root, temp_dir) { //recursive function for creating directory and generating markdown pages
|
async _markdown_recurse(root, temp_dir) { //recursive function for creating directory and generating markdown pages
|
||||||
console.log('root', root)
|
const fs = require('fs').promises
|
||||||
const Page = this.models.get('api:Page')
|
const Page = this.models.get('api:Page')
|
||||||
const child = await Page.find({ UUID: { $in: root.ChildPageIds } })
|
const child = await Page.find({ UUID: { $in: root.ChildPageIds } })
|
||||||
|
|
||||||
for (const page of child) {
|
for (const page of child) {
|
||||||
const markdown = this._generate_markdown(page)
|
const markdown = await this._generate_markdown(page)
|
||||||
|
await fs.writeFile(path.resolve(temp_dir, page.Name.replace(/\s/g, '_')) + '.md', markdown)
|
||||||
if (page.ChildPageIds && page.ChildPageIds.length) {
|
if (page.ChildPageIds && page.ChildPageIds.length) {
|
||||||
const sub_temp_dir = path.resolve(temp_dir, page.Name.replace(/\s/g, '_'))
|
const sub_temp_dir = path.resolve(temp_dir, page.Name.replace(/\s/g, '_'))
|
||||||
|
// console.log(sub_temp_dir)
|
||||||
await fs.mkdir(sub_temp_dir)
|
await fs.mkdir(sub_temp_dir)
|
||||||
this._markdown_recurse(page, sub_temp_dir)
|
await this._markdown_recurse(page, sub_temp_dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,16 +93,19 @@ class Export extends Controller {
|
|||||||
const html_name = page.Name.replace(/\s/g, '_') + '.html'
|
const html_name = page.Name.replace(/\s/g, '_') + '.html'
|
||||||
mapping[page.UUID] = html_name
|
mapping[page.UUID] = html_name
|
||||||
}
|
}
|
||||||
const sidebar_html = this._generate_sidebar(page0) //generates the sidebar contents
|
console.log(page0)
|
||||||
|
const sidebar_html = await this._generate_sidebar(mapping, page0) //generates the sidebar contents
|
||||||
|
|
||||||
const temp_dir = path.resolve(os.tmpdir(), uuid()) //make temporary directory
|
const temp_dir = path.resolve(os.tmpdir(), uuid()) //make temporary directory
|
||||||
await fs.mkdir(temp_dir)
|
await fs.mkdir(temp_dir)
|
||||||
|
|
||||||
/* Generates html files from template */
|
/* Generates html files from template */
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
const fs = require('fs').promises
|
const fs = require('fs').promises
|
||||||
const contents = await fs.readFile('../assets/export-template.html')
|
const contents = (await fs.readFile(path.resolve(this.app.directories.assets, 'export-template.html'))).toString('utf8')
|
||||||
const content_html = this._generate_html(page)
|
console.log(page)
|
||||||
|
//console.log({contents})
|
||||||
|
const content_html = await this._generate_html(page)
|
||||||
|
//console.log({content_html, sidebar_html})
|
||||||
const page_html = contents.replace('%%SIDEBAR%%', sidebar_html).replace('%%CONTENTS%%', content_html)
|
const page_html = contents.replace('%%SIDEBAR%%', sidebar_html).replace('%%CONTENTS%%', content_html)
|
||||||
await fs.writeFile(path.resolve(temp_dir, mapping[page.UUID]), page_html)
|
await fs.writeFile(path.resolve(temp_dir, mapping[page.UUID]), page_html)
|
||||||
}
|
}
|
||||||
@ -112,18 +117,21 @@ class Export extends Controller {
|
|||||||
return res.error(500);
|
return res.error(500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.sendFile(`${path.resolve(temp_dir, 'archive.zip')}`)
|
return res.sendFile(`${path.resolve(temp_dir, 'archive.zip')}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
async _generate_sidebar(root) { //generate sidebar from mapping array and root
|
async _generate_sidebar(mapping, upper_node) { //generate sidebar from mapping array and upper_node
|
||||||
if (root.ChildPageIds < 1) {
|
const Page = this.models.get('api:Page')
|
||||||
return '<a class="nav-link" href="' + mapping[root.UUID] + '">' + root.Name + '</a>'
|
console.log(upper_node)
|
||||||
|
console.log(upper_node.ChildPageIds == 'undefined')
|
||||||
|
if (upper_node.ChildPageIds == 'undefined') {
|
||||||
|
return '<a class="nav-link" href="' + mapping[upper_node.UUID] + '">' + upper_node.Name + '</a>'
|
||||||
} else {
|
} else {
|
||||||
let base = '<nav class="nav nav-pills flex-column">'
|
let base = '<nav class="nav nav-pills flex-column">'
|
||||||
for (const childrenId of root.ChildPageIds) {
|
for (const childrenId of upper_node.ChildPageIds) {
|
||||||
base += this._generate_sidebar(await Page.findOne({ UUID: childrenId }))
|
base += (await this._generate_sidebar(await Page.findOne({ UUID: childrenId })))
|
||||||
}
|
}
|
||||||
|
console.log({ base })
|
||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const Controller = require('libflitter/controller/Controller')
|
const Controller = require('libflitter/controller/Controller');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Home Controller
|
* Home Controller
|
||||||
@ -8,25 +8,27 @@ const Controller = require('libflitter/controller/Controller')
|
|||||||
*/
|
*/
|
||||||
class Home extends Controller {
|
class Home extends Controller {
|
||||||
static get services() {
|
static get services() {
|
||||||
return [...super.services, 'configs']
|
return [...super.services, 'configs'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Serve the main welcome page.
|
* Serve the main welcome page.
|
||||||
*/
|
*/
|
||||||
welcome(req, res) {
|
welcome(req, res) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the welcome view.
|
* Return the welcome view.
|
||||||
* The page() method is added by Flitter and passes some
|
* The page() method is added by Flitter and passes some
|
||||||
* helpful contextual data to the view as well.
|
* helpful contextual data to the view as well.
|
||||||
*/
|
*/
|
||||||
return res.page('welcome', {user: req.user})
|
return res.page('welcome', { user: req.user });
|
||||||
}
|
}
|
||||||
async get_login(req, res) {
|
async get_login(req, res) {
|
||||||
const AppName = this.configs.get('app.name')
|
const AppName = this.configs.get('app.name');
|
||||||
return res.page('login', {AppName})
|
return res.page('login', { AppName });
|
||||||
|
}
|
||||||
|
toApp(req, res) {
|
||||||
|
return res.redirect('/i');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Home
|
module.exports = Home;
|
||||||
|
@ -15,36 +15,33 @@
|
|||||||
* /auth/register
|
* /auth/register
|
||||||
*/
|
*/
|
||||||
const index = {
|
const index = {
|
||||||
|
|
||||||
prefix: '/auth',
|
prefix: '/auth',
|
||||||
|
|
||||||
middleware: [
|
middleware: [],
|
||||||
|
|
||||||
],
|
|
||||||
|
|
||||||
get: {
|
get: {
|
||||||
'/:provider/register': [
|
'/:provider/register': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'middleware::auth:ProviderRegistrationEnabled',
|
'middleware::auth:ProviderRegistrationEnabled',
|
||||||
'controller::auth:Forms.registration_provider_get',
|
'controller::auth:Forms.registration_provider_get'
|
||||||
],
|
],
|
||||||
'/register': [
|
'/register': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'middleware::auth:ProviderRegistrationEnabled',
|
'middleware::auth:ProviderRegistrationEnabled',
|
||||||
'controller::auth:Forms.registration_provider_get',
|
'controller::auth:Forms.registration_provider_get'
|
||||||
],
|
],
|
||||||
|
|
||||||
'/:provider/login': [
|
'/:provider/login': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'controller::auth:Forms.login_provider_get',
|
'controller::auth:Forms.login_provider_get'
|
||||||
],
|
],
|
||||||
'/login': [
|
'/login': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'controller::auth:Forms.login_provider_get',
|
'controller::auth:Forms.login_provider_get'
|
||||||
],
|
],
|
||||||
|
|
||||||
'/:provider/logout': [
|
'/:provider/logout': [
|
||||||
@ -56,14 +53,14 @@ const index = {
|
|||||||
// and before the user is allowed to continue. You can use it to add your own
|
// and before the user is allowed to continue. You can use it to add your own
|
||||||
// custom middleware for auth flow handling.
|
// custom middleware for auth flow handling.
|
||||||
|
|
||||||
'controller::auth:Forms.logout_provider_present_success',
|
'controller::auth:Forms.logout_provider_present_success'
|
||||||
],
|
],
|
||||||
'/logout': [
|
'/logout': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:UserOnly',
|
'middleware::auth:UserOnly',
|
||||||
'controller::auth:Forms.logout_provider_clean_session',
|
'controller::auth:Forms.logout_provider_clean_session',
|
||||||
'controller::auth:Forms.logout_provider_present_success',
|
'controller::auth:Forms.logout_provider_present_success'
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
post: {
|
post: {
|
||||||
@ -72,42 +69,42 @@ const index = {
|
|||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'middleware::auth:ProviderRegistrationEnabled',
|
'middleware::auth:ProviderRegistrationEnabled',
|
||||||
'controller::auth:Forms.registration_provider_create_user',
|
'controller::auth:Forms.registration_provider_create_user',
|
||||||
'controller::auth:Forms.registration_provider_present_user_created',
|
'controller::auth:Forms.registration_provider_present_user_created'
|
||||||
],
|
],
|
||||||
'/register': [
|
'/register': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'middleware::auth:ProviderRegistrationEnabled',
|
'middleware::auth:ProviderRegistrationEnabled',
|
||||||
'controller::auth:Forms.registration_provider_create_user',
|
'controller::auth:Forms.registration_provider_create_user',
|
||||||
'controller::auth:Forms.registration_provider_present_user_created',
|
'controller::auth:Forms.registration_provider_present_user_created'
|
||||||
],
|
],
|
||||||
|
|
||||||
'/:provider/login': [
|
'/:provider/login': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'controller::auth:Forms.login_provider_authenticate_user',
|
'controller::auth:Forms.login_provider_authenticate_user',
|
||||||
'controller::auth:Forms.login_provider_present_success',
|
'controller::auth:Forms.login_provider_present_success'
|
||||||
],
|
],
|
||||||
'/login': [
|
'/login': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:GuestOnly',
|
'middleware::auth:GuestOnly',
|
||||||
'controller::auth:Forms.login_provider_authenticate_user',
|
'controller::auth:Forms.login_provider_authenticate_user',
|
||||||
'controller::auth:Forms.login_provider_present_success',
|
'controller::auth:Forms.login_provider_present_success'
|
||||||
],
|
],
|
||||||
|
|
||||||
'/:provider/logout': [
|
'/:provider/logout': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:UserOnly',
|
'middleware::auth:UserOnly',
|
||||||
'controller::auth:Forms.logout_provider_clean_session',
|
'controller::auth:Forms.logout_provider_clean_session',
|
||||||
'controller::auth:Forms.logout_provider_present_success',
|
'controller::auth:Forms.logout_provider_present_success'
|
||||||
],
|
],
|
||||||
'/logout': [
|
'/logout': [
|
||||||
'middleware::auth:ProviderRoute',
|
'middleware::auth:ProviderRoute',
|
||||||
'middleware::auth:UserOnly',
|
'middleware::auth:UserOnly',
|
||||||
'controller::auth:Forms.logout_provider_clean_session',
|
'controller::auth:Forms.logout_provider_clean_session',
|
||||||
'controller::auth:Forms.logout_provider_present_success',
|
'controller::auth:Forms.logout_provider_present_success'
|
||||||
],
|
]
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = exports = index
|
module.exports = exports = index;
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
* defined here, but no logic should occur.
|
* defined here, but no logic should occur.
|
||||||
*/
|
*/
|
||||||
const index = {
|
const index = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the prefix applied to each of these routes.
|
* Define the prefix applied to each of these routes.
|
||||||
* For example, if prefix is '/auth':
|
* For example, if prefix is '/auth':
|
||||||
@ -44,7 +43,7 @@ const index = {
|
|||||||
|
|
||||||
// Placeholder for auth dashboard. You'd replace this with
|
// Placeholder for auth dashboard. You'd replace this with
|
||||||
// your own route protected by 'middleware::auth:UserOnly'
|
// your own route protected by 'middleware::auth:UserOnly'
|
||||||
'/dash': [ 'controller::Home.welcome' ],
|
'/dash': ['controller::Home.toApp'],
|
||||||
'/login': ['middleware::auth:GuestOnly', 'controller::Home.get_login'],
|
'/login': ['middleware::auth:GuestOnly', 'controller::Home.get_login'],
|
||||||
'/test-json': ['controller::Export.json_export'],
|
'/test-json': ['controller::Export.json_export'],
|
||||||
'/test-markdown': ['controller::Export.markdown_export'],
|
'/test-markdown': ['controller::Export.markdown_export'],
|
||||||
@ -58,9 +57,7 @@ const index = {
|
|||||||
* an array of canonical references to controller methods
|
* an array of canonical references to controller methods
|
||||||
* or middleware that are applied in order.
|
* or middleware that are applied in order.
|
||||||
*/
|
*/
|
||||||
post: {
|
post: {}
|
||||||
|
};
|
||||||
|
|
||||||
},
|
module.exports = exports = index;
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = exports = index
|
|
||||||
|
@ -37,10 +37,10 @@ html
|
|||||||
body
|
body
|
||||||
.flitter-container
|
.flitter-container
|
||||||
img.flitter-image(src="/assets/logo/3x/logo3x.png")
|
img.flitter-image(src="/assets/logo/3x/logo3x.png")
|
||||||
a.flitter-name(href="https://hack20.glmdev.tech/i" target="_blank") powered by #{_app.name}
|
a.flitter-name(href="/login" target="_blank") powered by #{_app.name}
|
||||||
if user
|
if user
|
||||||
.flitter-container
|
.flitter-container
|
||||||
p.flitter-text Welcome, #{user.uid}! <a href="/auth/logout">Log out.</a>
|
p.flitter-text Welcome, #{user.uid}! <a href="/auth/logout">Log out.</a>
|
||||||
else
|
else
|
||||||
.flitter-container
|
.flitter-container
|
||||||
p.flitter-text New to #{_app.name}? <a href="https://hack20.glmdev.tech/login" target="_blank">Start here.</a>
|
p.flitter-text New to #{_app.name}? <a href=/login" target="_blank">Start here.</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user