Need a backend to integrate with b2.
This commit is contained in:
parent
8ccd782ead
commit
14bef7168a
@ -6,15 +6,16 @@
|
|||||||
"author": "Timothy Farrell <tim@thecookiejar.me> (https://github.com/explorigin)",
|
"author": "Timothy Farrell <tim@thecookiejar.me> (https://github.com/explorigin)",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "webpack",
|
||||||
"dev": "webpack-dev-server"
|
"dev": "webpack-dev-server"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"css-loader": "^0.28.7",
|
"body-parser": "~1.18.3",
|
||||||
"date-fns": "~1.29.0",
|
"date-fns": "~1.29.0",
|
||||||
"domvm": "~3.2.1",
|
"domvm": "~3.2.1",
|
||||||
"exif-parser": "~0.1.9",
|
"exif-parser": "~0.1.9",
|
||||||
"extract-text-webpack-plugin": "^3.0.2",
|
|
||||||
"frptools": "3.1.1",
|
"frptools": "3.1.1",
|
||||||
|
"express": "~4.16.3",
|
||||||
"linear-partitioning": "0.3.2",
|
"linear-partitioning": "0.3.2",
|
||||||
"pica": "~2.0.8",
|
"pica": "~2.0.8",
|
||||||
"pouchdb-adapter-http": "~6.4.1",
|
"pouchdb-adapter-http": "~6.4.1",
|
||||||
@ -33,8 +34,13 @@
|
|||||||
"styletron-utils": "^2.5.4"
|
"styletron-utils": "^2.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"html-webpack-plugin": "^2.30.1",
|
"css-loader": "~0.28.11",
|
||||||
"webpack": "~3.8.1",
|
"extract-text-webpack-plugin": "~4.0.0-beta.0",
|
||||||
"webpack-dev-server": "~2.9.2"
|
"file-loader": "~1.1.11",
|
||||||
|
"html-webpack-plugin": "~3.2.0",
|
||||||
|
"url-loader": "~1.0.1",
|
||||||
|
"webpack": "~4.10.2",
|
||||||
|
"webpack-cli": "~2.1.5",
|
||||||
|
"webpack-dev-server": "~3.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
packages/gallery/scripts/b2/bucket_setup_examples.sh
Executable file
49
packages/gallery/scripts/b2/bucket_setup_examples.sh
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Fill these in
|
||||||
|
ACCOUNT_ID=""
|
||||||
|
APPLICATION_KEY=""
|
||||||
|
BUCKET_ID=""
|
||||||
|
|
||||||
|
# These need to be populated by get account token
|
||||||
|
API_HOST="https://api001.backblazeb2.com"
|
||||||
|
ACCOUNT_AUTHORIZATION_TOKEN=""
|
||||||
|
|
||||||
|
# Get account token
|
||||||
|
# curl "https://api.backblazeb2.com/b2api/v1/b2_authorize_account" -u "$ACCOUNT_ID:$APPLICATION_KEY"
|
||||||
|
|
||||||
|
|
||||||
|
# Read CORS rules on bucket
|
||||||
|
# curl \
|
||||||
|
# -H "Authorization: $ACCOUNT_AUTHORIZATION_TOKEN" \
|
||||||
|
# -d "{\"accountId\": \"$ACCOUNT_ID\", \"bucketTypes\": [\"allPrivate\",\"allPublic\"]}" \
|
||||||
|
# "$API_HOST/b2api/v1/b2_list_buckets"
|
||||||
|
|
||||||
|
|
||||||
|
# Set CORS rules on bucket
|
||||||
|
# read -d "" UPDATE_BUCKET_JSON << EOF
|
||||||
|
# {
|
||||||
|
# "accountId": "$ACCOUNT_ID",
|
||||||
|
# "bucketId": "$BUCKET_ID",
|
||||||
|
# "corsRules": [
|
||||||
|
# {
|
||||||
|
# "allowedHeaders": ["*"],
|
||||||
|
# "allowedOperations": [
|
||||||
|
# "b2_download_file_by_id",
|
||||||
|
# "b2_download_file_by_name",
|
||||||
|
# "b2_upload_file"
|
||||||
|
# ],
|
||||||
|
# "allowedOrigins": [
|
||||||
|
# "*"
|
||||||
|
# ],
|
||||||
|
# "corsRuleName": "downloadFromAnyOrigin",
|
||||||
|
# "exposeHeaders": null,
|
||||||
|
# "maxAgeSeconds": 3600
|
||||||
|
# }
|
||||||
|
# ]
|
||||||
|
# }
|
||||||
|
# EOF
|
||||||
|
# curl \
|
||||||
|
# -H "Authorization: $ACCOUNT_AUTHORIZATION_TOKEN" \
|
||||||
|
# -d "$UPDATE_BUCKET_JSON" \
|
||||||
|
# "$API_HOST/b2api/v1/b2_update_bucket"
|
||||||
65
packages/gallery/src/server.js
Normal file
65
packages/gallery/src/server.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const request = require('request');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const B2_BASE_URL = 'https://api.backblazeb2.com/b2api/v1/';
|
||||||
|
|
||||||
|
// App
|
||||||
|
const app = express();
|
||||||
|
app.use(bodyParser.text());
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
express.static('.', {
|
||||||
|
dotfiles: 'ignore',
|
||||||
|
etag: false,
|
||||||
|
index: ['src/index.html']
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
app.get('/api/v1/authorize_account', (req, res) => {
|
||||||
|
const auth = req.get('Authorization');
|
||||||
|
|
||||||
|
request(
|
||||||
|
{
|
||||||
|
url: B2_BASE_URL + 'b2_authorize_account',
|
||||||
|
headers: { Authorization: auth }
|
||||||
|
},
|
||||||
|
function(error, response, body) {
|
||||||
|
res.set(response.headers);
|
||||||
|
res.send(body);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/v1/get_upload_url', (req, res) => {
|
||||||
|
request.post(
|
||||||
|
{
|
||||||
|
url: req.get('apiUrl') + '/b2api/v1/b2_get_upload_url',
|
||||||
|
headers: { Authorization: req.get('Authorization') },
|
||||||
|
body: req.body
|
||||||
|
},
|
||||||
|
function(error, response, body) {
|
||||||
|
res.send(body);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/v1/remove_file', (req, res) => {
|
||||||
|
request.post(
|
||||||
|
{
|
||||||
|
url: req.get('apiUrl') + '/b2api/v1/b2_delete_file_version',
|
||||||
|
headers: { Authorization: req.get('Authorization') },
|
||||||
|
body: req.body
|
||||||
|
},
|
||||||
|
function(error, response, body) {
|
||||||
|
res.send(body);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
app: app
|
||||||
|
};
|
||||||
@ -2,9 +2,14 @@ const path = require('path');
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const server = require('./src/server.js');
|
||||||
|
|
||||||
|
const API_PORT = 8888;
|
||||||
|
const API_HOST = '127.0.0.1';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
context: path.resolve(__dirname, './src'),
|
context: path.resolve(__dirname, './src'),
|
||||||
|
mode: 'development',
|
||||||
entry: {
|
entry: {
|
||||||
app: './app.js',
|
app: './app.js',
|
||||||
sw: './sw.js'
|
sw: './sw.js'
|
||||||
@ -15,9 +20,19 @@ module.exports = {
|
|||||||
publicPath: '/'
|
publicPath: '/'
|
||||||
},
|
},
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.resolve(__dirname, './src'),
|
before: () => {
|
||||||
|
server.app.listen(API_PORT, API_HOST);
|
||||||
|
console.log(`Running api host on ${API_HOST}:${API_PORT}`);
|
||||||
|
},
|
||||||
|
contentBase: path.join(__dirname, 'dist'),
|
||||||
|
host: '0.0.0.0',
|
||||||
|
https: true,
|
||||||
headers: {
|
headers: {
|
||||||
'Service-Worker-Allowed': '/'
|
'Service-Worker-Allowed': '/',
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
},
|
||||||
|
proxy: {
|
||||||
|
'/api': `http://${API_HOST}:${API_PORT}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
@ -28,6 +43,15 @@ module.exports = {
|
|||||||
fallback: 'style-loader',
|
fallback: 'style-loader',
|
||||||
use: 'css-loader'
|
use: 'css-loader'
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
// fonts
|
||||||
|
{
|
||||||
|
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||||
|
loader: 'url-loader?limit=10000&minetype=application/font-woff'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
||||||
|
loader: 'file-loader'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user