Skip to content

Commit 21798f6

Browse files
author
CI Fix
committed
lint issues
1 parent 7afef98 commit 21798f6

File tree

137 files changed

+2331
-2205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2331
-2205
lines changed

bin/lib/cli-utils.mjs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import fs from 'fs-extra';
2-
import { red, cyan, bold } from 'colorette';
3-
import { URL } from 'url';
4-
import LDP from '../../lib/ldp.mjs';
5-
import AccountManager from '../../lib/models/account-manager.mjs';
6-
import SolidHost from '../../lib/models/solid-host.mjs';
1+
import fs from 'fs-extra'
2+
import { red, cyan, bold } from 'colorette'
3+
import { URL } from 'url'
4+
import LDP from '../../lib/ldp.mjs'
5+
import AccountManager from '../../lib/models/account-manager.mjs'
6+
import SolidHost from '../../lib/models/solid-host.mjs'
77

8-
export function getAccountManager(config, options = {}) {
9-
const ldp = options.ldp || new LDP(config);
10-
const host = options.host || SolidHost.from({ port: config.port, serverUri: config.serverUri });
8+
export function getAccountManager (config, options = {}) {
9+
const ldp = options.ldp || new LDP(config)
10+
const host = options.host || SolidHost.from({ port: config.port, serverUri: config.serverUri })
1111
return AccountManager.from({
1212
host,
1313
store: ldp,
1414
multiuser: config.multiuser
15-
});
15+
})
1616
}
1717

18-
export function loadConfig(program, options) {
18+
export function loadConfig (program, options) {
1919
let argv = {
2020
...options,
2121
version: program.version()
22-
};
23-
const configFile = argv.configFile || './config.json';
22+
}
23+
const configFile = argv.configFile || './config.json'
2424
try {
25-
const file = fs.readFileSync(configFile);
26-
const config = JSON.parse(file);
27-
argv = { ...config, ...argv };
25+
const file = fs.readFileSync(configFile)
26+
const config = JSON.parse(file)
27+
argv = { ...config, ...argv }
2828
} catch (err) {
2929
if (typeof argv.configFile !== 'undefined') {
3030
if (!fs.existsSync(configFile)) {
31-
console.log(red(bold('ERR')), 'Config file ' + configFile + " doesn't exist.");
32-
process.exit(1);
31+
console.log(red(bold('ERR')), 'Config file ' + configFile + " doesn't exist.")
32+
process.exit(1)
3333
}
3434
}
3535
if (fs.existsSync(configFile)) {
36-
console.log(red(bold('ERR')), 'config file ' + configFile + " couldn't be parsed: " + err);
37-
process.exit(1);
36+
console.log(red(bold('ERR')), 'config file ' + configFile + " couldn't be parsed: " + err)
37+
process.exit(1)
3838
}
39-
console.log(cyan(bold('TIP')), 'create a config.json: `$ solid init`');
39+
console.log(cyan(bold('TIP')), 'create a config.json: `$ solid init`')
4040
}
41-
return argv;
41+
return argv
4242
}
4343

44-
export function loadAccounts({ root, serverUri, hostname }) {
45-
const files = fs.readdirSync(root);
46-
hostname = hostname || new URL(serverUri).hostname;
47-
const isUserDirectory = new RegExp(`.${hostname}$`);
48-
return files.filter(file => isUserDirectory.test(file));
44+
export function loadAccounts ({ root, serverUri, hostname }) {
45+
const files = fs.readdirSync(root)
46+
hostname = hostname || new URL(serverUri).hostname
47+
const isUserDirectory = new RegExp(`.${hostname}$`)
48+
return files.filter(file => isUserDirectory.test(file))
4949
}
5050

51-
export function loadUsernames({ root, serverUri }) {
52-
const hostname = new URL(serverUri).hostname;
53-
return loadAccounts({ root, hostname }).map(userDirectory => userDirectory.substr(0, userDirectory.length - hostname.length - 1));
51+
export function loadUsernames ({ root, serverUri }) {
52+
const hostname = new URL(serverUri).hostname
53+
return loadAccounts({ root, hostname }).map(userDirectory => userDirectory.substr(0, userDirectory.length - hostname.length - 1))
5454
}

bin/lib/init.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs'
33
import options from './options.mjs'
44
import camelize from 'camelize'
55

6-
let questions = options
6+
const questions = options
77
.map((option) => {
88
if (!option.type) {
99
if (option.flag) {
@@ -91,4 +91,3 @@ function manipulateServerSection (answers) {
9191
}
9292
})
9393
}
94-

bin/lib/invalidUsernames.mjs

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import fs from 'fs-extra';
2-
import Handlebars from 'handlebars';
3-
import path from 'path';
4-
import { getAccountManager, loadConfig, loadUsernames } from './cli-utils.mjs';
5-
import { isValidUsername } from '../../lib/common/user-utils.mjs';
6-
import blacklistService from '../../lib/services/blacklist-service.mjs';
7-
import { initConfigDir, initTemplateDirs } from '../../lib/server-config.mjs';
8-
import { fromServerConfig } from '../../lib/models/oidc-manager.mjs';
9-
import EmailService from '../../lib/services/email-service.mjs';
10-
import SolidHost from '../../lib/models/solid-host.mjs';
1+
import fs from 'fs-extra'
2+
import Handlebars from 'handlebars'
3+
import path from 'path'
4+
import { getAccountManager, loadConfig, loadUsernames } from './cli-utils.mjs'
5+
import { isValidUsername } from '../../lib/common/user-utils.mjs'
6+
import blacklistService from '../../lib/services/blacklist-service.mjs'
7+
import { initConfigDir, initTemplateDirs } from '../../lib/server-config.mjs'
8+
import { fromServerConfig } from '../../lib/models/oidc-manager.mjs'
9+
import EmailService from '../../lib/services/email-service.mjs'
10+
import SolidHost from '../../lib/models/solid-host.mjs'
1111

1212
export default function (program) {
1313
program
@@ -16,121 +16,121 @@ export default function (program) {
1616
.option('--delete', 'Will delete users with usernames that are invalid')
1717
.description('Manage usernames that are invalid')
1818
.action(async (options) => {
19-
const config = loadConfig(program, options);
19+
const config = loadConfig(program, options)
2020
if (!config.multiuser) {
21-
return console.error('You are running a single user server, no need to check for invalid usernames');
21+
return console.error('You are running a single user server, no need to check for invalid usernames')
2222
}
23-
const invalidUsernames = getInvalidUsernames(config);
24-
const host = SolidHost.from({ port: config.port, serverUri: config.serverUri });
25-
const accountManager = getAccountManager(config, { host });
23+
const invalidUsernames = getInvalidUsernames(config)
24+
const host = SolidHost.from({ port: config.port, serverUri: config.serverUri })
25+
const accountManager = getAccountManager(config, { host })
2626
if (options.notify) {
27-
return notifyUsers(invalidUsernames, accountManager, config);
27+
return notifyUsers(invalidUsernames, accountManager, config)
2828
}
2929
if (options.delete) {
30-
return deleteUsers(invalidUsernames, accountManager, config, host);
30+
return deleteUsers(invalidUsernames, accountManager, config, host)
3131
}
32-
listUsernames(invalidUsernames);
33-
});
32+
listUsernames(invalidUsernames)
33+
})
3434
}
3535

36-
function backupIndexFile(username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail) {
37-
const userDirectory = accountManager.accountDirFor(username);
38-
const currentIndex = path.join(userDirectory, 'index.html');
39-
const currentIndexExists = fs.existsSync(currentIndex);
40-
const backupIndex = path.join(userDirectory, 'index.backup.html');
41-
const backupIndexExists = fs.existsSync(backupIndex);
36+
function backupIndexFile (username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail) {
37+
const userDirectory = accountManager.accountDirFor(username)
38+
const currentIndex = path.join(userDirectory, 'index.html')
39+
const currentIndexExists = fs.existsSync(currentIndex)
40+
const backupIndex = path.join(userDirectory, 'index.backup.html')
41+
const backupIndexExists = fs.existsSync(backupIndex)
4242
if (currentIndexExists && !backupIndexExists) {
43-
fs.renameSync(currentIndex, backupIndex);
44-
createNewIndexAcl(userDirectory);
45-
createNewIndex(username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex);
46-
console.info(`index.html updated for user ${username}`);
43+
fs.renameSync(currentIndex, backupIndex)
44+
createNewIndexAcl(userDirectory)
45+
createNewIndex(username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex)
46+
console.info(`index.html updated for user ${username}`)
4747
}
4848
}
4949

50-
function createNewIndex(username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex) {
50+
function createNewIndex (username, invalidUsernameTemplate, dateOfRemoval, supportEmail, currentIndex) {
5151
const newIndexSource = invalidUsernameTemplate({
5252
username,
5353
dateOfRemoval,
5454
supportEmail
55-
});
56-
fs.writeFileSync(currentIndex, newIndexSource, 'utf-8');
55+
})
56+
fs.writeFileSync(currentIndex, newIndexSource, 'utf-8')
5757
}
5858

59-
function createNewIndexAcl(userDirectory) {
60-
const currentIndexAcl = path.join(userDirectory, 'index.html.acl');
61-
const backupIndexAcl = path.join(userDirectory, 'index.backup.html.acl');
62-
const currentIndexSource = fs.readFileSync(currentIndexAcl, 'utf-8');
63-
const backupIndexSource = currentIndexSource.replace(/index.html/g, 'index.backup.html');
64-
fs.writeFileSync(backupIndexAcl, backupIndexSource, 'utf-8');
59+
function createNewIndexAcl (userDirectory) {
60+
const currentIndexAcl = path.join(userDirectory, 'index.html.acl')
61+
const backupIndexAcl = path.join(userDirectory, 'index.backup.html.acl')
62+
const currentIndexSource = fs.readFileSync(currentIndexAcl, 'utf-8')
63+
const backupIndexSource = currentIndexSource.replace(/index.html/g, 'index.backup.html')
64+
fs.writeFileSync(backupIndexAcl, backupIndexSource, 'utf-8')
6565
}
6666

67-
async function deleteUsers(usernames, accountManager, config, host) {
68-
const oidcManager = fromServerConfig({ ...config, host });
67+
async function deleteUsers (usernames, accountManager, config, host) {
68+
const oidcManager = fromServerConfig({ ...config, host })
6969
const deletingUsers = usernames.map(async username => {
7070
try {
71-
const user = accountManager.userAccountFrom({ username });
72-
await oidcManager.users.deleteUser(user);
71+
const user = accountManager.userAccountFrom({ username })
72+
await oidcManager.users.deleteUser(user)
7373
} catch (error) {
7474
if (error.message !== 'No email given') {
75-
throw error;
75+
throw error
7676
}
7777
}
78-
const userDirectory = accountManager.accountDirFor(username);
79-
await fs.remove(userDirectory);
80-
});
81-
await Promise.all(deletingUsers);
82-
console.info(`Deleted ${deletingUsers.length} users succeeded`);
78+
const userDirectory = accountManager.accountDirFor(username)
79+
await fs.remove(userDirectory)
80+
})
81+
await Promise.all(deletingUsers)
82+
console.info(`Deleted ${deletingUsers.length} users succeeded`)
8383
}
8484

85-
function getInvalidUsernames(config) {
86-
const usernames = loadUsernames(config);
87-
return usernames.filter(username => !isValidUsername(username) || !blacklistService.validate(username));
85+
function getInvalidUsernames (config) {
86+
const usernames = loadUsernames(config)
87+
return usernames.filter(username => !isValidUsername(username) || !blacklistService.validate(username))
8888
}
8989

90-
function listUsernames(usernames) {
90+
function listUsernames (usernames) {
9191
if (usernames.length === 0) {
92-
return console.info('No invalid usernames was found');
92+
return console.info('No invalid usernames was found')
9393
}
94-
console.info(`${usernames.length} invalid usernames were found:${usernames.map(username => `\n- ${username}`)}`);
94+
console.info(`${usernames.length} invalid usernames were found:${usernames.map(username => `\n- ${username}`)}`)
9595
}
9696

97-
async function notifyUsers(usernames, accountManager, config) {
98-
const twoWeeksFromNow = Date.now() + 14 * 24 * 60 * 60 * 1000;
99-
const dateOfRemoval = (new Date(twoWeeksFromNow)).toLocaleDateString();
100-
const { supportEmail } = config;
101-
updateIndexFiles(usernames, accountManager, dateOfRemoval, supportEmail);
102-
await sendEmails(config, usernames, accountManager, dateOfRemoval, supportEmail);
97+
async function notifyUsers (usernames, accountManager, config) {
98+
const twoWeeksFromNow = Date.now() + 14 * 24 * 60 * 60 * 1000
99+
const dateOfRemoval = (new Date(twoWeeksFromNow)).toLocaleDateString()
100+
const { supportEmail } = config
101+
updateIndexFiles(usernames, accountManager, dateOfRemoval, supportEmail)
102+
await sendEmails(config, usernames, accountManager, dateOfRemoval, supportEmail)
103103
}
104104

105-
async function sendEmails(config, usernames, accountManager, dateOfRemoval, supportEmail) {
105+
async function sendEmails (config, usernames, accountManager, dateOfRemoval, supportEmail) {
106106
if (config.email && config.email.host) {
107-
const configPath = initConfigDir(config);
108-
const templates = initTemplateDirs(configPath);
107+
const configPath = initConfigDir(config)
108+
const templates = initTemplateDirs(configPath)
109109
const users = await Promise.all(await usernames.map(async username => {
110-
const emailAddress = await accountManager.loadAccountRecoveryEmail({ username });
111-
const accountUri = accountManager.accountUriFor(username);
112-
return { username, emailAddress, accountUri };
113-
}));
114-
const emailService = new EmailService(templates.email, config.email);
110+
const emailAddress = await accountManager.loadAccountRecoveryEmail({ username })
111+
const accountUri = accountManager.accountUriFor(username)
112+
return { username, emailAddress, accountUri }
113+
}))
114+
const emailService = new EmailService(templates.email, config.email)
115115
const sendingEmails = users
116116
.filter(user => !!user.emailAddress)
117117
.map(user => emailService.sendWithTemplate('invalid-username.mjs', {
118118
to: user.emailAddress,
119119
accountUri: user.accountUri,
120120
dateOfRemoval,
121121
supportEmail
122-
}));
123-
const emailsSent = await Promise.all(sendingEmails);
124-
console.info(`${emailsSent.length} emails sent to users with invalid usernames`);
125-
return;
122+
}))
123+
const emailsSent = await Promise.all(sendingEmails)
124+
console.info(`${emailsSent.length} emails sent to users with invalid usernames`)
125+
return
126126
}
127-
console.info('You have not configured an email service.');
128-
console.info('Please set it up to send users email about their accounts');
127+
console.info('You have not configured an email service.')
128+
console.info('Please set it up to send users email about their accounts')
129129
}
130130

131-
function updateIndexFiles(usernames, accountManager, dateOfRemoval, supportEmail) {
132-
const invalidUsernameFilePath = path.join(process.cwd(), 'default-views', 'account', 'invalid-username.hbs');
133-
const source = fs.readFileSync(invalidUsernameFilePath, 'utf-8');
134-
const invalidUsernameTemplate = Handlebars.compile(source);
135-
usernames.forEach(username => backupIndexFile(username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail));
131+
function updateIndexFiles (usernames, accountManager, dateOfRemoval, supportEmail) {
132+
const invalidUsernameFilePath = path.join(process.cwd(), 'default-views', 'account', 'invalid-username.hbs')
133+
const source = fs.readFileSync(invalidUsernameFilePath, 'utf-8')
134+
const invalidUsernameTemplate = Handlebars.compile(source)
135+
usernames.forEach(username => backupIndexFile(username, accountManager, invalidUsernameTemplate, dateOfRemoval, supportEmail))
136136
}

0 commit comments

Comments
 (0)