mirror of
https://github.com/usatiuk/photos.git
synced 2025-10-28 23:37:48 +01:00
add SIGNUP_ALLOWED switch
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
Something that tries to be a self-hosted alternative to Google Photos
|
Something that tries to be a self-hosted alternative to Google Photos
|
||||||
|
|
||||||
Demo: https://photos.usatiuk.com
|
Demo: https://photos.usatiuk.com
|
||||||
(data is stored on tmpfs, reset every day)
|
(no need to enter a real email, something like asdf@asdf.com is enough, data is stored on tmpfs, reset every day)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ Also, you need to run database migrations with
|
|||||||
Then start with `npm run dev` and visit http://localhost:1234 (Parcel dev server
|
Then start with `npm run dev` and visit http://localhost:1234 (Parcel dev server
|
||||||
is listening at http://localhost:1234, and koa at http://localhost:3000)
|
is listening at http://localhost:1234, and koa at http://localhost:3000)
|
||||||
|
|
||||||
## Actually hosting this thing
|
## Actually hosting this
|
||||||
|
|
||||||
The suggested way to host this is, agian, using Docker: you can find a
|
The suggested way to host this is, agian, using Docker: you can find a
|
||||||
docker-compose example in `dockercomposeexample` folder
|
docker-compose example in `dockercomposeexample` folder
|
||||||
@@ -51,7 +51,9 @@ docker-compose example in `dockercomposeexample` folder
|
|||||||
|
|
||||||
* `JWT_SECRET` - JWT secret - set it to something random
|
* `JWT_SECRET` - JWT secret - set it to something random
|
||||||
|
|
||||||
* `HTTPS` (`"yes"`/`"no"`) - whether the server enforce HTTPS or not
|
* `HTTPS` (`"yes"`/`"no"`) - whether the server enforces HTTPS or not
|
||||||
|
|
||||||
|
* `SIGNUP_ALLOWED` (`"yes"`/`"no"`) - whether signups are allowed or not, persistent
|
||||||
|
|
||||||
* `API_ROOT`
|
* `API_ROOT`
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export enum ConfigKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDBConfig {
|
export interface IDBConfig {
|
||||||
signupAllowed: boolean;
|
signupAllowed: "yes" | "no";
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultValues: Record<ConfigKey, string> = {
|
const defaultValues: Record<ConfigKey, string> = {
|
||||||
@@ -70,6 +70,8 @@ export async function setConfigValue(
|
|||||||
let pair = await Config.findOne({ key });
|
let pair = await Config.findOne({ key });
|
||||||
if (!pair) {
|
if (!pair) {
|
||||||
pair = new Config(key, val);
|
pair = new Config(key, val);
|
||||||
|
} else {
|
||||||
|
pair.value = val;
|
||||||
}
|
}
|
||||||
await pair.save();
|
await pair.save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,44 @@
|
|||||||
|
import { Config, ConfigKey, setConfigValue } from "~entity/Config";
|
||||||
import { app } from "./app";
|
import { app } from "./app";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
import { connect } from "./config/database";
|
import { connect } from "./config/database";
|
||||||
|
|
||||||
|
async function readConfig() {
|
||||||
|
if (process.env.SIGNUP_ALLOWED) {
|
||||||
|
if (process.env.SIGNUP_ALLOWED === "yes") {
|
||||||
|
await setConfigValue(ConfigKey.signupAllowed, "yes");
|
||||||
|
console.log("Signups enabled");
|
||||||
|
} else if (process.env.SIGNUP_ALLOWED === "no") {
|
||||||
|
await setConfigValue(ConfigKey.signupAllowed, "no");
|
||||||
|
console.log("Signups disabled");
|
||||||
|
} else {
|
||||||
|
await setConfigValue(ConfigKey.signupAllowed, "no");
|
||||||
|
console.log("Signups disabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function dumpConfig() {
|
||||||
|
console.log("Running with config:");
|
||||||
|
//TODO: not print sensitive values
|
||||||
|
for (const entry of await Config.find()) {
|
||||||
|
console.log(`${entry.key} = ${entry.value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
connect()
|
connect()
|
||||||
.then((connection) => {
|
.then((connection) => {
|
||||||
console.log(`Connected to ${connection.name}`);
|
console.log(`Connected to ${connection.name}`);
|
||||||
app.listen(config.port);
|
const startApp = () => {
|
||||||
console.log(`Listening at ${config.port}`);
|
app.listen(config.port);
|
||||||
|
console.log(`Listening at ${config.port}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
readConfig()
|
||||||
|
.then(() =>
|
||||||
|
dumpConfig()
|
||||||
|
.then(() => startApp())
|
||||||
|
.catch((e) => console.log(e)),
|
||||||
|
)
|
||||||
|
.catch((e) => console.log(e));
|
||||||
})
|
})
|
||||||
.catch((e) => console.log(e));
|
.catch((e) => console.log(e));
|
||||||
|
|||||||
Reference in New Issue
Block a user