added travis and converted to single quotes
This commit is contained in:
parent
31a83b883d
commit
a9601eb68b
|
@ -0,0 +1,10 @@
|
|||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 13
|
||||
|
||||
install:
|
||||
- npm ci
|
||||
|
||||
script:
|
||||
- npm test
|
|
@ -1,22 +1,22 @@
|
|||
import {terser} from "rollup-plugin-terser";
|
||||
import resolve from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import {terser} from 'rollup-plugin-terser';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
|
||||
const isProd = process.env.NODE_ENV === "production";
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
const typescriptOptions = {include: ["src/**/*", "../shared/**/*"]};
|
||||
const typescriptOptions = {include: ['src/**/*', '../shared/**/*']};
|
||||
if (!isProd) typescriptOptions.noEmitOnError = false;
|
||||
|
||||
module.exports = {
|
||||
input: "src/client.js",
|
||||
input: 'src/client.js',
|
||||
plugins: [
|
||||
commonjs(),
|
||||
resolve(),
|
||||
isProd && terser()
|
||||
],
|
||||
output: {
|
||||
file: "dist/client/bundle.js",
|
||||
name: "ucaptcha",
|
||||
format: "iife"
|
||||
file: 'dist/client/bundle.js',
|
||||
name: 'ucaptcha',
|
||||
format: 'iife'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,8 +15,5 @@ module.exports = {
|
|||
"sourceType": "module",
|
||||
},
|
||||
"plugins": [],
|
||||
"rules": {
|
||||
"quotes": ["error", "double"],
|
||||
"comma-dangle": "off"
|
||||
},
|
||||
"rules": {},
|
||||
};
|
||||
|
|
6
src/R.js
6
src/R.js
|
@ -1,8 +1,8 @@
|
|||
import path from "path";
|
||||
import { fileURLToPath } from 'url';
|
||||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
const __dirname = fileURLToPath(import.meta.url);
|
||||
/**
|
||||
* A path string relative to the project folder.
|
||||
* @typedef {String} IMAGES_FOLDER
|
||||
*/
|
||||
export const IMAGES_FOLDER = path.join(__dirname, "..", "public", "images");
|
||||
export const IMAGES_FOLDER = path.join(__dirname, '..', 'public', 'images');
|
|
@ -1,4 +1,4 @@
|
|||
import UserSession from "./shared/models/UserSession.js";
|
||||
import UserSession from './shared/models/UserSession.js';
|
||||
|
||||
/**
|
||||
* Create a uCaptcha box
|
||||
|
@ -6,8 +6,8 @@ import UserSession from "./shared/models/UserSession.js";
|
|||
* @return {HTMLElement} uCaptcha box
|
||||
*/
|
||||
function uCaptchaBox(key) {
|
||||
const checkbox = createElement("div", {
|
||||
style: "cursor:pointer;border-radius:3px;border:2px solid #888;width:25px;height:25px;display:inline-block"
|
||||
const checkbox = createElement('div', {
|
||||
style: 'cursor:pointer;border-radius:3px;border:2px solid #888;width:25px;height:25px;display:inline-block',
|
||||
});
|
||||
checkbox.onclick = function() {
|
||||
fetch(`https://localhost:444/api/init?k=${key}`)
|
||||
|
@ -19,10 +19,10 @@ function uCaptchaBox(key) {
|
|||
session.deserialize(resp);
|
||||
});
|
||||
|
||||
checkbox.setAttribute("style",
|
||||
checkbox.getAttribute("style") + "background-color:royalblue;");
|
||||
checkbox.setAttribute('style',
|
||||
checkbox.getAttribute('style') + 'background-color:royalblue;');
|
||||
};
|
||||
const captchaBox = createElement("div");
|
||||
const captchaBox = createElement('div');
|
||||
captchaBox.appendChild(checkbox);
|
||||
return captchaBox;
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ export function create(websiteKey, selector) {
|
|||
*/
|
||||
function createElement(tagName, attributes={}) {
|
||||
const elem = document.createElement(tagName);
|
||||
for(const [name, value] of Object.entries(attributes)) {
|
||||
for (const [name, value] of Object.entries(attributes)) {
|
||||
elem.setAttribute(name, value);
|
||||
}
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import cron from "cron";
|
||||
import cron from 'cron';
|
||||
const CronJob = cron.CronJob;
|
||||
import request from "request";
|
||||
import path from "path";
|
||||
import {IMAGES_FOLDER} from "../R.js";
|
||||
import {randomBytes} from "./utils.js";
|
||||
import Jimp from "jimp";
|
||||
import request from 'request';
|
||||
import path from 'path';
|
||||
import {IMAGES_FOLDER} from '../R.js';
|
||||
import {randomBytes} from './utils.js';
|
||||
import Jimp from 'jimp';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ async function saveImage(filepath, uri) {
|
|||
const geoImageRequestDefaults = {
|
||||
lat: 40.6971576,
|
||||
lng: -83.608754,
|
||||
radius: 5000
|
||||
radius: 5000,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -85,12 +85,12 @@ const geoImageRequestDefaults = {
|
|||
* @param {geoImageRequest} [geoImageRequest] - Optional set a geoImageReqest
|
||||
*/
|
||||
export function fetchImages(geoImageRequest) {
|
||||
console.log("Collecting images...");
|
||||
console.log('Collecting images...');
|
||||
const formData = {
|
||||
...geoImageRequestDefaults,
|
||||
...geoImageRequest
|
||||
...geoImageRequest,
|
||||
};
|
||||
request("https://openstreetcam.org/1.0/list/nearby-photos/", {formData, method: "POST"}, async (apiError, _, body) => {
|
||||
request('https://openstreetcam.org/1.0/list/nearby-photos/', {formData, method: 'POST'}, async (apiError, _, body) => {
|
||||
if (apiError) throw apiError;
|
||||
/** @type {OSCResponse} */
|
||||
const json = JSON.parse(body);
|
||||
|
@ -102,12 +102,12 @@ export function fetchImages(geoImageRequest) {
|
|||
});
|
||||
}
|
||||
|
||||
export const fetchImagesJob = new CronJob("0 0 0 * * *", () => {
|
||||
export const fetchImagesJob = new CronJob('0 0 0 * * *', () => {
|
||||
fetchImages(geoImageRequestDefaults);
|
||||
}, null, true);
|
||||
|
||||
|
||||
export default {
|
||||
fetchImages,
|
||||
fetchImagesJob
|
||||
fetchImagesJob,
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* @param {object} json
|
||||
*/
|
||||
export default (res, json) => {
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(`:)${JSON.stringify(json)}`);
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import crypto from "crypto";
|
||||
import crypto from 'crypto';
|
||||
|
||||
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabc" +
|
||||
"defghijklmnopqrstuvwxyz0123456789";
|
||||
const alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabc' +
|
||||
'defghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
/**
|
||||
* Produce a string of n length consisting of alphanumeric characters
|
||||
|
@ -16,7 +16,7 @@ function randomBytes(length) {
|
|||
chars.push(alphabets[bytes[i] % alphabets.length]);
|
||||
}
|
||||
|
||||
return chars.join("");
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import express from "express";
|
||||
import {initializer} from "./initializeSession.js";
|
||||
import sendJson from "../../helpers/sendJson.js";
|
||||
import express from 'express';
|
||||
import {initializer} from './initializeSession.js';
|
||||
import sendJson from '../../helpers/sendJson.js';
|
||||
|
||||
const router = express.Router();
|
||||
const router = new express.Router();
|
||||
|
||||
router.get("/init", async (req, res)=>{
|
||||
router.get('/init', async (req, res)=>{
|
||||
const result = await initializer();
|
||||
sendJson(res, result);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* TODO: this code should maybe be the constructor of a session model
|
||||
*/
|
||||
import pickRandomFile from "./pickRandomFile.js";
|
||||
import UserSession from "../../shared/models/UserSession.js";
|
||||
import {randomBytes} from "../../helpers/utils.js";
|
||||
import pickRandomFile from './pickRandomFile.js';
|
||||
import UserSession from '../../shared/models/UserSession.js';
|
||||
import {randomBytes} from '../../helpers/utils.js';
|
||||
|
||||
/**
|
||||
* @return {any}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import Jimp from "jimp";
|
||||
import {promisify} from "util";
|
||||
import {IMAGES_FOLDER} from "../../R.js";
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import Jimp from 'jimp';
|
||||
import {promisify} from 'util';
|
||||
import {IMAGES_FOLDER} from '../../R.js';
|
||||
|
||||
const readdirAsync = promisify(fs.readdir);
|
||||
|
||||
|
@ -17,8 +17,8 @@ export default async () => {
|
|||
const randomFilePath = path.join(
|
||||
IMAGES_FOLDER,
|
||||
files[Math.floor(
|
||||
Math.random() * files.length
|
||||
)]
|
||||
Math.random() * files.length,
|
||||
)],
|
||||
);
|
||||
return randomFilePath;
|
||||
};
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
import dotenv from "dotenv";
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import express from "express";
|
||||
import express from 'express';
|
||||
const app = express();
|
||||
|
||||
app.disable("x-powered-by");
|
||||
app.disable('x-powered-by');
|
||||
|
||||
import cookieParser from "cookie-parser";
|
||||
import cookieParser from 'cookie-parser';
|
||||
app.use(cookieParser(process.env.COOKIE_SECRET));
|
||||
|
||||
app.use(express.json({
|
||||
limit: "128kb"
|
||||
limit: '128kb',
|
||||
}));
|
||||
|
||||
import apis from "./routes/api/index.js";
|
||||
app.use("/api", apis);
|
||||
import apis from './routes/api/index.js';
|
||||
app.use('/api', apis);
|
||||
|
||||
import {fetchImagesJob, fetchImages} from "./helpers/fetchImagesJob.js";
|
||||
import {fetchImagesJob, fetchImages} from './helpers/fetchImagesJob.js';
|
||||
|
||||
app.listen(8080, ()=>{
|
||||
fetchImagesJob.start();
|
||||
// fetchImages({radius: 1000});
|
||||
console.log("Server started");
|
||||
console.log("=========================================================");
|
||||
console.log('Server started');
|
||||
console.log('=========================================================');
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ export class Session {
|
|||
* @param {string} id
|
||||
*/
|
||||
set sessionId(id) {
|
||||
if (id.length !== 8) throw Error("ClientID is not 8 characters");
|
||||
if (id.length !== 8) throw Error('ClientID is not 8 characters');
|
||||
this._sessionId = id;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ export class Session {
|
|||
serialize() {
|
||||
const {sessionId, imageUrl} = this;
|
||||
if (!sessionId || !imageUrl) {
|
||||
throw Error("Unable to serialize because of missing field(s)");
|
||||
throw Error('Unable to serialize because of missing field(s)');
|
||||
}
|
||||
return [sessionId, imageUrl];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue