@@ -2,7 +2,6 @@ const fs = require('fs-extra')
22const Handlebars = require ( 'handlebars' )
33const path = require ( 'path' )
44const { URL } = require ( 'url' )
5- const util = require ( 'util' )
65
76const { loadConfig } = require ( './common' )
87const { isValidUsername } = require ( '../../lib/common/user-utils' )
@@ -15,22 +14,19 @@ const EmailService = require('../../lib/services/email-service')
1514const LDP = require ( '../../lib/ldp' )
1615const SolidHost = require ( '../../lib/models/solid-host' )
1716
18- const fileExists = util . promisify ( fs . exists )
19- const fileRename = util . promisify ( fs . rename )
20-
2117module . exports = function ( program ) {
2218 program
2319 . command ( 'invalidusernames' )
2420 . option ( '--notify' , 'Will notify users with usernames that are invalid' )
2521 . option ( '--delete' , 'Will delete users with usernames that are invalid' )
2622 . description ( 'Manage usernames that are invalid' )
2723 . action ( async ( options ) => {
28- const config = await loadConfig ( program , options )
24+ const config = loadConfig ( program , options )
2925 if ( ! config . multiuser ) {
3026 return console . error ( 'You are running a single user server, no need to check for invalid usernames' )
3127 }
3228
33- const invalidUsernames = await getInvalidUsernames ( config )
29+ const invalidUsernames = getInvalidUsernames ( config )
3430 const host = SolidHost . from ( { port : config . port , serverUri : config . serverUri } )
3531 const accountManager = getAccountManager ( config , host )
3632
@@ -42,18 +38,21 @@ module.exports = function (program) {
4238 return deleteUsers ( invalidUsernames , accountManager , config , host )
4339 }
4440
45- listUsernames ( listUsernames )
41+ listUsernames ( invalidUsernames )
4642 } )
4743}
4844
49- async function createNewIndexFile ( username , accountManager , invalidUsernameTemplate , dateOfRemoval , supportEmail , fileOptions ) {
45+ function createNewIndexFile ( username , accountManager , invalidUsernameTemplate , dateOfRemoval , supportEmail , fileOptions ) {
5046 const userDirectory = accountManager . accountDirFor ( username )
5147 const currentIndex = path . join ( userDirectory , 'index.html' )
52- const currentIndexExists = await fileExists ( currentIndex )
48+ const currentIndexExists = fs . existsSync ( currentIndex )
49+ const currentIndexAcl = path . join ( userDirectory , 'index.html.acl' )
5350 const backupIndex = path . join ( userDirectory , 'index.backup.html' )
54- const backupIndexExists = await fileExists ( backupIndex )
51+ const backupIndexExists = fs . existsSync ( backupIndex )
52+ const backupIndexAcl = path . join ( userDirectory , 'index.backup.html.acl' )
5553 if ( currentIndexExists && ! backupIndexExists ) {
56- await fileRename ( currentIndex , backupIndex )
54+ fs . renameSync ( currentIndex , backupIndex )
55+ fs . copyFileSync ( currentIndexAcl , backupIndexAcl )
5756 const newIndexSource = invalidUsernameTemplate ( {
5857 username,
5958 dateOfRemoval,
@@ -96,8 +95,8 @@ function getAccountManager (config, host) {
9695 } )
9796}
9897
99- async function getInvalidUsernames ( config ) {
100- const files = await util . promisify ( fs . readdir ) ( config . root )
98+ function getInvalidUsernames ( config ) {
99+ const files = fs . readdirSync ( config . root )
101100 const hostname = new URL ( config . serverUri ) . hostname
102101 const isUserDirectory = new RegExp ( `.${ hostname } $` )
103102 return files
@@ -108,7 +107,7 @@ async function getInvalidUsernames (config) {
108107
109108function listUsernames ( usernames ) {
110109 if ( usernames . length === 0 ) {
111- console . info ( 'No invalid usernames was found' )
110+ return console . info ( 'No invalid usernames was found' )
112111 }
113112 console . info ( `${ usernames . length } invalid usernames were found:${ usernames . map ( username => `\n- ${ username } ` ) } ` )
114113}
@@ -118,7 +117,7 @@ async function notifyUsers (usernames, accountManager, config) {
118117 const dateOfRemoval = ( new Date ( twoWeeksFromNow ) ) . toLocaleDateString ( )
119118 const { supportEmail } = config
120119
121- await updateIndexFiles ( usernames , accountManager , dateOfRemoval , supportEmail )
120+ updateIndexFiles ( usernames , accountManager , dateOfRemoval , supportEmail )
122121 await sendEmails ( config , usernames , accountManager , dateOfRemoval , supportEmail )
123122}
124123
@@ -132,9 +131,9 @@ async function sendEmails (config, usernames, accountManager, dateOfRemoval, sup
132131 return { username, emailAddress, accountUri }
133132 } ) )
134133 const emailService = new EmailService ( templates . email , config . email )
135- const sendingEmails = await users
134+ const sendingEmails = users
136135 . filter ( user => ! ! user . emailAddress )
137- . map ( async user => await emailService . sendWithTemplate ( 'invalid-username' , {
136+ . map ( user => emailService . sendWithTemplate ( 'invalid-username' , {
138137 to : user . emailAddress ,
139138 accountUri : user . accountUri ,
140139 dateOfRemoval,
@@ -148,13 +147,12 @@ async function sendEmails (config, usernames, accountManager, dateOfRemoval, sup
148147 console . info ( 'Please set it up to send users email about their accounts' )
149148}
150149
151- async function updateIndexFiles ( usernames , accountManager , dateOfRemoval , supportEmail ) {
152- const invalidUsernameFilePath = path . join ( process . cwd ( ) , 'default-views/ account/ invalid-username.hbs' )
150+ function updateIndexFiles ( usernames , accountManager , dateOfRemoval , supportEmail ) {
151+ const invalidUsernameFilePath = path . join ( process . cwd ( ) , 'default-views' , ' account' , ' invalid-username.hbs')
153152 const fileOptions = {
154153 encoding : 'utf-8'
155154 }
156155 const source = fs . readFileSync ( invalidUsernameFilePath , fileOptions )
157156 const invalidUsernameTemplate = Handlebars . compile ( source )
158- const updatingFiles = usernames . map ( username => createNewIndexFile ( username , accountManager , invalidUsernameTemplate , dateOfRemoval , supportEmail , fileOptions ) )
159- return Promise . all ( updatingFiles )
157+ usernames . forEach ( username => createNewIndexFile ( username , accountManager , invalidUsernameTemplate , dateOfRemoval , supportEmail , fileOptions ) )
160158}
0 commit comments