Skip to content

Commit

Permalink
Write to CSV index file on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnl committed Jul 8, 2024
1 parent e6085f6 commit 421c03a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const memeChannelId = process.env.MEME_CHANNEL_ID
const token = process.env.DISCORD_BOT_TOKEN
const uploadDirectory = process.env.UPLOAD_DIR || 'public/'
const htaccessPath = process.env.HTACCESS_PATH || 'public/.htaccess'
const indexPath = process.env.INDEX_PATH || 'public/indeksi.csv'
const selectedLanguage = process.env.LANGUAGE || 'english'

const selectedTranslations = translatedMessages[selectedLanguage]
Expand Down Expand Up @@ -79,6 +80,10 @@ client.on('message', async (message) => {
fsp.appendFile(htaccessPath,
`AddDescription "${utils.alphanum(message.author.username) || "matti"}" ${availableFilename}\n`)

// Add item to the index
fsp.appendFile(indexPath,
`"${availableFilename}";"${message.author.username}";"${utils.currentTimestamp()}"\n`)

console.log(`Successfully uploaded ${availableFilename} by ${message.author.tag}`)
} catch (e) {
const errorMessage = await message.reply(`${selectedTranslations.uploadError}: ${e.message}`)
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export const findAvailableFilename = async (folder, fullFilename) => {
if (!fs.existsSync(path.join(folder, filename))) return filename
}
}

export const currentTimestamp = () => new Date().toISOString().replace('T', ' ').replace('Z', '0000000000')

0 comments on commit 421c03a

Please sign in to comment.