mirror of
1
2
Fork 0

added travis and converted to single quotes

This commit is contained in:
Devshh 2020-03-16 16:51:34 +05:30
parent 31a83b883d
commit a9601eb68b
13 changed files with 76 additions and 68 deletions

10
.travis.yml Normal file
View File

@ -0,0 +1,10 @@
language: node_js
node_js:
- 13
install:
- npm ci
script:
- npm test

View File

@ -1,22 +1,22 @@
import {terser} from "rollup-plugin-terser"; import {terser} from 'rollup-plugin-terser';
import resolve from "@rollup/plugin-node-resolve"; import resolve from '@rollup/plugin-node-resolve';
import commonjs from "@rollup/plugin-commonjs"; 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; if (!isProd) typescriptOptions.noEmitOnError = false;
module.exports = { module.exports = {
input: "src/client.js", input: 'src/client.js',
plugins: [ plugins: [
commonjs(), commonjs(),
resolve(), resolve(),
isProd && terser() isProd && terser()
], ],
output: { output: {
file: "dist/client/bundle.js", file: 'dist/client/bundle.js',
name: "ucaptcha", name: 'ucaptcha',
format: "iife" format: 'iife'
} }
}; };

View File

@ -15,8 +15,5 @@ module.exports = {
"sourceType": "module", "sourceType": "module",
}, },
"plugins": [], "plugins": [],
"rules": { "rules": {},
"quotes": ["error", "double"],
"comma-dangle": "off"
},
}; };

View File

@ -1,8 +1,8 @@
import path from "path"; import path from 'path';
import { fileURLToPath } from 'url'; import {fileURLToPath} from 'url';
const __dirname = fileURLToPath(import.meta.url); const __dirname = fileURLToPath(import.meta.url);
/** /**
* A path string relative to the project folder. * A path string relative to the project folder.
* @typedef {String} IMAGES_FOLDER * @typedef {String} IMAGES_FOLDER
*/ */
export const IMAGES_FOLDER = path.join(__dirname, "..", "public", "images"); export const IMAGES_FOLDER = path.join(__dirname, '..', 'public', 'images');

View File

@ -1,4 +1,4 @@
import UserSession from "./shared/models/UserSession.js"; import UserSession from './shared/models/UserSession.js';
/** /**
* Create a uCaptcha box * Create a uCaptcha box
@ -6,8 +6,8 @@ import UserSession from "./shared/models/UserSession.js";
* @return {HTMLElement} uCaptcha box * @return {HTMLElement} uCaptcha box
*/ */
function uCaptchaBox(key) { function uCaptchaBox(key) {
const checkbox = createElement("div", { const checkbox = createElement('div', {
style: "cursor:pointer;border-radius:3px;border:2px solid #888;width:25px;height:25px;display:inline-block" style: 'cursor:pointer;border-radius:3px;border:2px solid #888;width:25px;height:25px;display:inline-block',
}); });
checkbox.onclick = function() { checkbox.onclick = function() {
fetch(`https://localhost:444/api/init?k=${key}`) fetch(`https://localhost:444/api/init?k=${key}`)
@ -19,10 +19,10 @@ function uCaptchaBox(key) {
session.deserialize(resp); session.deserialize(resp);
}); });
checkbox.setAttribute("style", checkbox.setAttribute('style',
checkbox.getAttribute("style") + "background-color:royalblue;"); checkbox.getAttribute('style') + 'background-color:royalblue;');
}; };
const captchaBox = createElement("div"); const captchaBox = createElement('div');
captchaBox.appendChild(checkbox); captchaBox.appendChild(checkbox);
return captchaBox; return captchaBox;
} }
@ -47,7 +47,8 @@ export function create(websiteKey, selector) {
*/ */
function createElement(tagName, attributes={}) { function createElement(tagName, attributes={}) {
const elem = document.createElement(tagName); 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); elem.setAttribute(name, value);
} }
return elem;
} }

View File

@ -1,10 +1,10 @@
import cron from "cron"; import cron from 'cron';
const CronJob = cron.CronJob; const CronJob = cron.CronJob;
import request from "request"; import request from 'request';
import path from "path"; import path from 'path';
import {IMAGES_FOLDER} from "../R.js"; import {IMAGES_FOLDER} from '../R.js';
import {randomBytes} from "./utils.js"; import {randomBytes} from './utils.js';
import Jimp from "jimp"; import Jimp from 'jimp';
/** /**
@ -77,7 +77,7 @@ async function saveImage(filepath, uri) {
const geoImageRequestDefaults = { const geoImageRequestDefaults = {
lat: 40.6971576, lat: 40.6971576,
lng: -83.608754, lng: -83.608754,
radius: 5000 radius: 5000,
}; };
/** /**
@ -85,12 +85,12 @@ const geoImageRequestDefaults = {
* @param {geoImageRequest} [geoImageRequest] - Optional set a geoImageReqest * @param {geoImageRequest} [geoImageRequest] - Optional set a geoImageReqest
*/ */
export function fetchImages(geoImageRequest) { export function fetchImages(geoImageRequest) {
console.log("Collecting images..."); console.log('Collecting images...');
const formData = { const formData = {
...geoImageRequestDefaults, ...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; if (apiError) throw apiError;
/** @type {OSCResponse} */ /** @type {OSCResponse} */
const json = JSON.parse(body); 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); fetchImages(geoImageRequestDefaults);
}, null, true); }, null, true);
export default { export default {
fetchImages, fetchImages,
fetchImagesJob fetchImagesJob,
}; };

View File

@ -3,7 +3,7 @@
* @param {object} json * @param {object} json
*/ */
export default (res, json) => { export default (res, json) => {
res.setHeader("Content-Type", "application/json"); res.setHeader('Content-Type', 'application/json');
res.send(`:)${JSON.stringify(json)}`); res.send(`:)${JSON.stringify(json)}`);
return; return;
}; };

View File

@ -1,7 +1,7 @@
import crypto from "crypto"; import crypto from 'crypto';
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabc" + const alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabc' +
"defghijklmnopqrstuvwxyz0123456789"; 'defghijklmnopqrstuvwxyz0123456789';
/** /**
* Produce a string of n length consisting of alphanumeric characters * Produce a string of n length consisting of alphanumeric characters
@ -16,7 +16,7 @@ function randomBytes(length) {
chars.push(alphabets[bytes[i] % alphabets.length]); chars.push(alphabets[bytes[i] % alphabets.length]);
} }
return chars.join(""); return chars.join('');
} }

View File

@ -1,10 +1,10 @@
import express from "express"; import express from 'express';
import {initializer} from "./initializeSession.js"; import {initializer} from './initializeSession.js';
import sendJson from "../../helpers/sendJson.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(); const result = await initializer();
sendJson(res, result); sendJson(res, result);
}); });

View File

@ -1,9 +1,9 @@
/** /**
* TODO: this code should maybe be the constructor of a session model * TODO: this code should maybe be the constructor of a session model
*/ */
import pickRandomFile from "./pickRandomFile.js"; import pickRandomFile from './pickRandomFile.js';
import UserSession from "../../shared/models/UserSession.js"; import UserSession from '../../shared/models/UserSession.js';
import {randomBytes} from "../../helpers/utils.js"; import {randomBytes} from '../../helpers/utils.js';
/** /**
* @return {any} * @return {any}

View File

@ -1,8 +1,8 @@
import fs from "fs"; import fs from 'fs';
import path from "path"; import path from 'path';
import Jimp from "jimp"; import Jimp from 'jimp';
import {promisify} from "util"; import {promisify} from 'util';
import {IMAGES_FOLDER} from "../../R.js"; import {IMAGES_FOLDER} from '../../R.js';
const readdirAsync = promisify(fs.readdir); const readdirAsync = promisify(fs.readdir);
@ -17,8 +17,8 @@ export default async () => {
const randomFilePath = path.join( const randomFilePath = path.join(
IMAGES_FOLDER, IMAGES_FOLDER,
files[Math.floor( files[Math.floor(
Math.random() * files.length Math.random() * files.length,
)] )],
); );
return randomFilePath; return randomFilePath;
}; };

View File

@ -1,26 +1,26 @@
import dotenv from "dotenv"; import dotenv from 'dotenv';
dotenv.config(); dotenv.config();
import express from "express"; import express from 'express';
const app = 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(cookieParser(process.env.COOKIE_SECRET));
app.use(express.json({ app.use(express.json({
limit: "128kb" limit: '128kb',
})); }));
import apis from "./routes/api/index.js"; import apis from './routes/api/index.js';
app.use("/api", apis); app.use('/api', apis);
import {fetchImagesJob, fetchImages} from "./helpers/fetchImagesJob.js"; import {fetchImagesJob, fetchImages} from './helpers/fetchImagesJob.js';
app.listen(8080, ()=>{ app.listen(8080, ()=>{
fetchImagesJob.start(); fetchImagesJob.start();
// fetchImages({radius: 1000}); // fetchImages({radius: 1000});
console.log("Server started"); console.log('Server started');
console.log("========================================================="); console.log('=========================================================');
}); });

View File

@ -13,7 +13,7 @@ export class Session {
* @param {string} id * @param {string} id
*/ */
set sessionId(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; this._sessionId = id;
} }
@ -48,7 +48,7 @@ export class Session {
serialize() { serialize() {
const {sessionId, imageUrl} = this; const {sessionId, imageUrl} = this;
if (!sessionId || !imageUrl) { 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]; return [sessionId, imageUrl];
} }