Skip to content

Commit

Permalink
feat: Upgrade deps, login fixes, hint on search page
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Oct 12, 2018
1 parent 074f1a7 commit fbff5fd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -24,23 +24,24 @@
"apkmirror-client": "github:mkg20001/apkmirror-client",
"bull": "^3.4.8",
"catbox-mongodb": "^4.2.0",
"hapi": "^17.5.4",
"hapi": "^17.6.0",
"hapi-auth-cookie": "^9.0.0",
"hapi-pino": "^5.1.0",
"hapi-spa-serve": "^0.1.1",
"hat": "0.0.3",
"inert": "^5.1.0",
"js-yaml": "^3.12.0",
"mkdirp": "^0.5.1",
"mongoose": "^5.2.16",
"pino": "^5.6.1",
"mongoose": "^5.3.2",
"pino": "^5.7.0",
"request": "^2.88.0",
"truncate": "^2.0.1",
"yargs": "^12.0.2"
},
"devDependencies": {
"parcel-bundler": "^1.9.7",
"parcel-bundler": "^1.10.3",
"parcel-plugin-pug-client": "^1.0.1",
"page": "^1.10.1",
"page": "^1.10.2",
"whatwg-fetch": "^3.0.0"
},
"repository": {
Expand Down
11 changes: 9 additions & 2 deletions public/main.js
Expand Up @@ -4,6 +4,7 @@

const page = require('page')
const $ = window.jQuery
const loginFirstVisit = window.location.pathname.startsWith('/login')

const version = require('../package.json').version
$('.version').text('v' + version)
Expand All @@ -20,7 +21,9 @@ let failedLogin = false
const api = (u, opt) => fetch(APIURL + u, Object.assign({credentials: 'include', redirect: 'manual'}, opt || {}))
.then(res => {
if (res.type === 'opaqueredirect') {
preLogin = page.current
if (page.current !== '/login') {
preLogin = page.current
}
page.redirect('/login')
return Promise.reject(new Error('Need login'))
}
Expand Down Expand Up @@ -63,7 +66,11 @@ page('/', middle('apps'), (ctx) => {

/* Login */
const tmplLogin = require('./templates/login.pug')
page('/login', (ctx) => {
page('/login', loginFirstVisit ? middle('isAuthenticated') : (ctx, next) => next(), (ctx) => {
if (ctx.api) {
return page.redirect('/')
}

$('.page').html(tmplLogin({}))
$('#loginForm').on('submit', e => {
e.preventDefault()
Expand Down
6 changes: 6 additions & 0 deletions public/templates/search.pug
Expand Up @@ -3,6 +3,12 @@ div(class="jumbotron")
form(id="search")
input(type="text", id="search-val", value=query)
input(type="submit", value="Search")
br
h4
ul
li Click the app name to visit the APKMirror.com page
li Click the plus to add the app to the repo

each result in results
div(class="jumbotron")
div(class="row")
Expand Down
37 changes: 10 additions & 27 deletions src/index.js
Expand Up @@ -3,6 +3,7 @@
const Hapi = require('hapi')
const Joi = require('joi')
const CatboxMongoDB = require('catbox-mongodb')
const SPA = require('hapi-spa-serve')

const mongoose = require('mongoose')
const {App, Variant} = require('./db')
Expand Down Expand Up @@ -46,6 +47,14 @@ module.exports = ({redis, mongodb, adminPW, secret, fdroidRepoPath, port, host,
}]
})

server.route({
method: 'GET',
path: '/isAuthenticated',
handler: async (request, h) => {
return request.auth.isAuthenticated
}
})

server.route({
method: 'GET',
path: '/search',
Expand Down Expand Up @@ -343,33 +352,7 @@ module.exports = ({redis, mongodb, adminPW, secret, fdroidRepoPath, port, host,
}
})

const assets = path.join(__dirname, '../assets')
server.route({
method: 'GET',
path: '/{param*}',
options: {
auth: {mode: 'optional'}
},
handler: async (request, h) => {
let p = path.join(assets, request.path)
if (fs.existsSync(p)) {
return h.file(p, {confine: false})
} else {
return h.file(path.join(assets, 'index.html'), {confine: false})
}
}
})

server.route({
method: 'GET',
path: '/',
options: {
auth: {mode: 'optional'}
},
handler: async (request, h) => {
return h.file(path.join(assets, 'index.html'), {confine: false})
}
})
SPA(server, {assets: path.join(__dirname, '../assets'), options: { auth: {mode: 'optional'} }})

await server.start()
upIntv = setInterval(updateCron, updateCheckInterval)
Expand Down

0 comments on commit fbff5fd

Please sign in to comment.