Skip to content

Commit

Permalink
Serve resized images dynamically on request (#94)
Browse files Browse the repository at this point in the history
* Added image upload to rest api

* Add file-loader and indexEntry

* Add file-loader and indexEntry

* Added delete file route

* Thumbnail creation with imagemagick

* Added unauthorized event

* Rebase to a new branch

* Revert Time.vue

* Enable friendly errors plugin
  • Loading branch information
nextchamp-saqib authored and netchampfaris committed Sep 29, 2018
1 parent 5e9428a commit 233ad5e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
6 changes: 5 additions & 1 deletion backends/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ module.exports = class HTTPClient extends Observable {
async fetch(url, args) {
args.headers = this.getHeaders();
let response = await frappe.fetch(url, args);
let data = await response.json();

if (response.status === 401) {
frappe.events.trigger('Unauthorized');
}

if (response.status !== 200) {
throw Error(data.error);
}
let data = await response.json();

return data;
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"electron-devtools-installer": "^2.2.4",
"express": "^4.16.2",
"feather-icons": "^4.7.3",
"file-loader": "^1.1.11",
"flatpickr": "^4.3.2",
"frappe-datatable": "^1.3.1",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"imagemagick": "^0.1.3",
"jquery": "^3.3.1",
"jwt-simple": "^0.5.1",
"luxon": "^1.0.0",
Expand All @@ -46,6 +48,7 @@
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"puppeteer": "^1.2.0",
"quickthumb": "^0.0.12",
"sass-loader": "^7.0.3",
"showdown": "^1.8.6",
"socket.io": "^2.0.4",
Expand Down
8 changes: 4 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const backends = {};
// const backends = {};
backends.sqlite = require('frappejs/backends/sqlite');
//backends.mysql = require('frappejs/backends/mysql');

const path = require('path');
const express = require('express');
const cors = require('cors');
const app = express();
Expand All @@ -18,6 +18,7 @@ const auth = require('./../auth/auth')();
const morgan = require('morgan');
const { addWebpackMiddleware } = require('../webpack/serve');
const { getAppConfig } = require('../webpack/utils');
const quickthumb = require('quickthumb')

frappe.conf = getAppConfig();

Expand All @@ -41,8 +42,7 @@ module.exports = {
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static(frappe.conf.distPath));

app.use('/static', express.static(frappe.conf.staticPath))
app.use('/static', quickthumb.static(path.resolve(frappe.conf.staticPath), { type: 'resize' }));

app.use(morgan('tiny'));

Expand Down
1 change: 0 additions & 1 deletion server/restAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,5 @@ module.exports = {
}
return response.json({});
}));

}
};
11 changes: 9 additions & 2 deletions webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ function getConfig() {
'css-loader',
'sass-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
}
]
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'deepmerge$': 'deepmerge/dist/umd.js'
'deepmerge$': 'deepmerge/dist/umd.js',
'@': resolveAppDir(appConfig.dev.srcDir)
}
},
plugins: [
Expand All @@ -71,7 +78,7 @@ function getConfig() {
}),
new plugins.VueLoader(),
new plugins.Html({
template: resolveAppDir('src/index.html')
template: resolveAppDir(appConfig.dev.entryHtml)
}),
new plugins.CaseSensitivePaths(),
new plugins.NamedModules(),
Expand Down

0 comments on commit 233ad5e

Please sign in to comment.