mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-03-21 17:44:49 -05:00
Made CDN disk path configurable, updated CDN config, updated examples
This commit is contained in:
parent
4cd1665c17
commit
20da652b38
|
|
@ -32,6 +32,10 @@
|
|||
"hcaptcha": {
|
||||
"secret": "0x0000000000000000000000000000000000000000"
|
||||
},
|
||||
"cdn_base": "https://example.com",
|
||||
"cdn": {
|
||||
"base_url": "https://local-cdn.example.com",
|
||||
"subdomain": "local-cdn",
|
||||
"disk_path": "/home/jon/pretend-cdn"
|
||||
},
|
||||
"website_base": "https://example.com"
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ PN_ACT_CONFIG_S3_ENDPOINT=nyc3.digitaloceanspaces.com
|
|||
PN_ACT_CONFIG_S3_ACCESS_KEY=ACCESS_KEY
|
||||
PN_ACT_CONFIG_S3_ACCESS_SECRET=ACCESS_SECRET
|
||||
PN_ACT_CONFIG_HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000
|
||||
PN_ACT_CONFIG_CDN_BASE=https://local-cdn.example.com
|
||||
PN_ACT_CONFIG_CDN_BASE_URL=https://local-cdn.example.com
|
||||
PN_ACT_CONFIG_CDN_SUBDOMAIN=local-cdn
|
||||
PN_ACT_CONFIG_CDN_DISK_PATH=/home/jon/pretend-cdn
|
||||
PN_ACT_CONFIG_WEBSITE_BASE=https://example.com
|
||||
|
|
@ -30,8 +30,10 @@ require('dotenv').config();
|
|||
* @property {string} [s3.secret] s3 access secret
|
||||
* @property {object} [hcaptcha] hCaptcha settings
|
||||
* @property {string} [hcaptcha.secret] hCaptcha secret
|
||||
* @property {string} [cdn_subdomain] Subdomain used for serving CDN contents when s3 is disabled
|
||||
* @property {string} cdn_base Base URL for CDN location
|
||||
* @property {object} cdn CDN config settings
|
||||
* @property {object} [cdn.subdomain] Subdomain used for serving CDN contents when s3 is disabled
|
||||
* @property {string} [cdn.disk_path] Fully qualified file system path for storing and reading local CDN contents
|
||||
* @property {string} cdn.base_url Base URL for CDN server
|
||||
* @property {string} website_base Base URL for service website (used with emails)
|
||||
*/
|
||||
|
||||
|
|
@ -63,7 +65,7 @@ const requiredFields = [
|
|||
['http.port', 'PN_ACT_CONFIG_HTTP_PORT', Number],
|
||||
['mongoose.uri', 'PN_ACT_CONFIG_MONGO_URI'],
|
||||
['mongoose.database', 'PN_ACT_CONFIG_MONGO_DB_NAME'],
|
||||
['cdn_base', 'PN_ACT_CONFIG_CDN_BASE']
|
||||
['cdn.base_url', 'PN_ACT_CONFIG_CDN_BASE_URL']
|
||||
];
|
||||
|
||||
function configure() {
|
||||
|
|
@ -109,7 +111,11 @@ function configure() {
|
|||
hcaptcha: {
|
||||
secret: process.env.PN_ACT_CONFIG_HCAPTCHA_SECRET
|
||||
},
|
||||
cdn_base: process.env.PN_ACT_CONFIG_CDN_BASE,
|
||||
cdn: {
|
||||
subdomain: process.env.PN_ACT_CONFIG_CDN_BASE,
|
||||
disk_path: process.env.PN_ACT_CONFIG_CDN_BASE,
|
||||
base_url: process.env.PN_ACT_CONFIG_CDN_BASE
|
||||
},
|
||||
website_base: process.env.PN_ACT_CONFIG_WEBSITE_BASE
|
||||
};
|
||||
} else {
|
||||
|
|
@ -304,13 +310,13 @@ function configure() {
|
|||
}
|
||||
|
||||
if (disabledFeatures.s3) {
|
||||
const cdnSubdomainCheck = get(config, 'cdn_subdomain');
|
||||
const cdnSubdomainCheck = get(config, 'cdn.subdomain');
|
||||
|
||||
if (!cdnSubdomainCheck || cdnSubdomainCheck.trim() === '') {
|
||||
if (usingEnv) {
|
||||
logger.error('s3 file storage is disabled and no CDN subdomain was set. Set the PN_ACT_CONFIG_CDN_SUBDOMAIN environment variable');
|
||||
} else {
|
||||
logger.error('s3 file storage is disabled and no CDN subdomain was set. Set cdn_subdomain in your config.json');
|
||||
logger.error('s3 file storage is disabled and no CDN subdomain was set. Set cdn.subdomain in your config.json');
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
|
|
@ -320,7 +326,7 @@ function configure() {
|
|||
logger.warn('Both s3 and Redis are disabled. Large CDN files will use the in-memory cache, which may result in high memory use. Please enable s3 if you\'re running a production server.');
|
||||
}
|
||||
|
||||
logger.warn(`s3 file storage disabled. Using disk-based file storage. Please ensure cdn_base config or PN_ACT_CONFIG_CDN_BASE env variable is set to point to this server with the subdomain being ${config.cdn_subdomain}`);
|
||||
logger.warn(`s3 file storage disabled. Using disk-based file storage. Please ensure cdn.base_url config or PN_ACT_CONFIG_CDN_BASE env variable is set to point to this server with the subdomain being ${config.cdn.subdomain}`);
|
||||
}
|
||||
|
||||
module.exports.config = config;
|
||||
|
|
|
|||
|
|
@ -172,9 +172,9 @@ async function getUserProfileJSONByPID(pid) {
|
|||
mii_image: {
|
||||
// Images MUST be loaded over HTTPS or console ignores them
|
||||
// Bunny CDN is the only CDN which seems to support TLS 1.0/1.1 (required)
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/standard.tga`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/standard.tga`,
|
||||
id: user.get('mii.image_id'),
|
||||
url: `${config.cdn_base}/mii/${user.pid}/standard.tga`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/standard.tga`,
|
||||
type: 'standard'
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ router.get('/', async (request, response) => {
|
|||
mii: {
|
||||
data: pnid.get('mii.data'),
|
||||
name: pnid.get('mii.name'),
|
||||
image_url: `${config.cdn_base}/mii/${pnid.get('pid')}/normal_face.png`
|
||||
image_url: `${config.cdn.base_url}/mii/${pnid.get('pid')}/normal_face.png`
|
||||
},
|
||||
flags: {
|
||||
marketing: pnid.get('flags.marketing')
|
||||
|
|
@ -111,7 +111,7 @@ router.post('/', async (request, response) => {
|
|||
mii: {
|
||||
data: pnid.get('mii.data'),
|
||||
name: pnid.get('mii.name'),
|
||||
image_url: `${config.cdn_base}/mii/${pnid.get('pid')}/normal_face.png`
|
||||
image_url: `${config.cdn.base_url}/mii/${pnid.get('pid')}/normal_face.png`
|
||||
},
|
||||
flags: {
|
||||
marketing: pnid.get('flags.marketing')
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ localcdn.use(routes.GET);
|
|||
const router = express.Router();
|
||||
|
||||
// Create subdomains
|
||||
logger.info(`[LOCAL-CDN] Creating '${config.cdn_subdomain}' subdomain`);
|
||||
router.use(subdomain(config.cdn_subdomain, localcdn));
|
||||
logger.info(`[LOCAL-CDN] Creating '${config.cdn.subdomain}' subdomain`);
|
||||
router.use(subdomain(config.cdn.subdomain, localcdn));
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -20,51 +20,51 @@ router.get('/', async (request, response) => {
|
|||
|
||||
const miiImages = [
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/normal_face.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/normal_face.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/normal_face.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/normal_face.png`,
|
||||
type: 'standard'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/frustrated.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/frustrated.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/frustrated.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/frustrated.png`,
|
||||
type: 'frustrated_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/smile_open_mouth.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/smile_open_mouth.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/smile_open_mouth.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/smile_open_mouth.png`,
|
||||
type: 'happy_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/wink_left.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/wink_left.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/wink_left.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/wink_left.png`,
|
||||
type: 'like_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/normal_face.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/normal_face.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/normal_face.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/normal_face.png`,
|
||||
type: 'normal_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/sorrow.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/sorrow.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/sorrow.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/sorrow.png`,
|
||||
type: 'puzzled_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/surprised_open_mouth.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/surprised_open_mouth.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/surprised_open_mouth.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/surprised_open_mouth.png`,
|
||||
type: 'surprised_face'
|
||||
},
|
||||
{
|
||||
cached_url: `${config.cdn_base}/mii/${user.pid}/body.png`,
|
||||
cached_url: `${config.cdn.base_url}/mii/${user.pid}/body.png`,
|
||||
id: mii.id,
|
||||
url: `${config.cdn_base}/mii/${user.pid}/body.png`,
|
||||
url: `${config.cdn.base_url}/mii/${user.pid}/body.png`,
|
||||
type: 'whole_body'
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ async function uploadCDNAsset(bucket, key, data, acl) {
|
|||
}
|
||||
|
||||
async function writeLocalCDNFile(key, data) {
|
||||
const filePath = `${__dirname}/../cdn/${key}`;
|
||||
const filePath = config.cdn.disk_path;
|
||||
const folder = path.dirname(filePath);
|
||||
|
||||
await fs.ensureDir(folder);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user