Skip to content

Commit

Permalink
Fix: Archive name being static
Browse files Browse the repository at this point in the history
  • Loading branch information
gazmull committed Oct 5, 2019
1 parent cc7f486 commit 555c7a4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CronJob } from 'cron';
import CloudStore from 'smcloudstore';

const auth: Auth = require('../auth');
const date = new Date().toISOString().split('T')[0];
const archiveName = `${auth.name ? `${auth.name}.` : ''}${date}.tgz`;
const date = () => new Date().toISOString().split('T')[0];
const archiveName = () => `${auth.name ? `${auth.name}.` : ''}${date()}.tgz`;

const exec = promisify(_exec);
const logger = new Winston('sati').logger;
Expand Down Expand Up @@ -129,18 +129,18 @@ async function sendToCloud (zip: Buffer) {
await store.ensureContainer(cloud.container.name, cloud.container.options);
logger.info(`Bucket ${cloud.container.name} is ensured.`);

logger.info(`Uploading archived backup to bucket ${cloud.container.name} as ${archiveName}...`);
logger.info(`Uploading archived backup to bucket ${cloud.container.name} as ${archiveName()}...`);
await store.putObject(
cloud.container.name,
archiveName,
archiveName(),
zip,
{
metadata: {
'Content-Type': 'application/gzip'
}
}
);
logger.info(`Uploaded ${archiveName} to bucket ${cloud.container.name}.`);
logger.info(`Uploaded ${archiveName()} to bucket ${cloud.container.name}.`);

await sendToDiscord(`Backup has been sent to ${cloud.provider} under ${cloud.container.name} as \`${archiveName}\`!`);
}
Expand All @@ -149,7 +149,7 @@ async function sendToDiscord (content: Buffer | string) {
const channel = await client.channels.fetch(auth.discord.channel) as TextChannel;

if (Buffer.isBuffer(content)) {
const attachment = new MessageAttachment(content, archiveName);
const attachment = new MessageAttachment(content, archiveName());

await channel.send('Here is the backup the you requested to me!', attachment);
logger.info('Backup sent to Discord channel.');
Expand Down

0 comments on commit 555c7a4

Please sign in to comment.