Import Instagram archive to a Bluesky account
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

Moved all configuration including simulate into the app config class.

+41 -8
+25
src/config.test.ts
··· 10 10 delete process.env.TEST_VIDEO_MODE; 11 11 delete process.env.TEST_IMAGE_MODE; 12 12 delete process.env.TEST_IMAGES_MODE; 13 + delete process.env.SIMULATE; 13 14 }); 14 15 15 16 afterEach(() => { ··· 20 21 test('should create config with all test modes disabled by default', () => { 21 22 const config = AppConfig.fromEnv(); 22 23 expect(config.isTestModeEnabled()).toBe(false); 24 + }); 25 + 26 + test('should create config with simulate mode disabled by default', () => { 27 + const config = AppConfig.fromEnv(); 28 + expect(config.isSimulateEnabled()).toBe(false); 23 29 }); 24 30 25 31 test('should enable test video mode when TEST_VIDEO_MODE=1', () => { ··· 38 44 process.env.TEST_IMAGES_MODE = '1'; 39 45 const config = AppConfig.fromEnv(); 40 46 expect(config.isTestModeEnabled()).toBe(true); 47 + }); 48 + 49 + test('should enable simulate mode when SIMULATE=1', () => { 50 + process.env.SIMULATE = '1'; 51 + const config = AppConfig.fromEnv(); 52 + expect(config.isSimulateEnabled()).toBe(true); 41 53 }); 42 54 }); 43 55 ··· 107 119 const config = AppConfig.fromEnv(); 108 120 expect(config.isTestModeEnabled()).toBe(true); 109 121 }); 122 + }); 123 + }); 124 + 125 + describe('isSimulateEnabled', () => { 126 + test('should return false when simulate mode is not enabled', () => { 127 + const config = AppConfig.fromEnv(); 128 + expect(config.isSimulateEnabled()).toBe(false); 129 + }); 130 + 131 + test('should return true when simulate mode is enabled', () => { 132 + process.env.SIMULATE = '1'; 133 + const config = AppConfig.fromEnv(); 134 + expect(config.isSimulateEnabled()).toBe(true); 110 135 }); 111 136 }); 112 137 });
+12 -1
src/config.ts
··· 10 10 private readonly testVideoMode: boolean; 11 11 private readonly testImageMode: boolean; 12 12 private readonly testImagesMode: boolean; 13 + private readonly simulate: boolean; 13 14 14 15 constructor(config: { 15 16 testVideoMode: boolean; 16 17 testImageMode: boolean; 17 18 testImagesMode: boolean; 19 + simulate: boolean; 18 20 }) { 19 21 this.testVideoMode = config.testVideoMode; 20 22 this.testImageMode = config.testImageMode; 21 23 this.testImagesMode = config.testImagesMode; 24 + this.simulate = config.simulate; 22 25 } 23 26 24 27 /** ··· 28 31 return new AppConfig({ 29 32 testVideoMode: process.env.TEST_VIDEO_MODE === '1', 30 33 testImageMode: process.env.TEST_IMAGE_MODE === '1', 31 - testImagesMode: process.env.TEST_IMAGES_MODE === '1' 34 + testImagesMode: process.env.TEST_IMAGES_MODE === '1', 35 + simulate: process.env.SIMULATE === '1' 32 36 }); 33 37 } 34 38 ··· 37 41 */ 38 42 isTestModeEnabled(): boolean { 39 43 return this.testVideoMode || this.testImageMode || this.testImagesMode; 44 + } 45 + 46 + /** 47 + * Checks if simulate mode is enabled 48 + */ 49 + isSimulateEnabled(): boolean { 50 + return this.simulate; 40 51 } 41 52 42 53 /**
+4 -7
src/instagram-to-bluesky.ts
··· 1 - import * as dotenv from 'dotenv'; 2 1 import FS from 'fs'; 3 2 import path from 'path'; 4 3 import * as process from 'process'; ··· 15 14 import { InstagramExportedPost } from './media/InstagramExportedPost'; 16 15 import { decodeUTF8, InstagramMediaProcessor } from './media/media'; 17 16 18 - dotenv.config(); 19 17 20 18 const API_RATE_LIMIT_DELAY = 3000; // https://docs.bsky.app/docs/advanced-guides/rate-limits 21 19 ··· 113 111 * 114 112 */ 115 113 export async function main() { 116 - const SIMULATE = process.env.SIMULATE === "1"; 117 114 const config = AppConfig.fromEnv(); 118 115 config.validate(); 119 116 ··· 134 131 username: process.env.BLUESKY_USERNAME, 135 132 MIN_DATE, 136 133 MAX_DATE, 137 - SIMULATE, 134 + SIMULATE: config.isSimulateEnabled(), 138 135 }); 139 136 140 137 // Setup BlueSky Client only used if SIMULATE is not configured. 141 138 let bluesky: BlueskyClient | null = null; 142 139 143 - if (!SIMULATE) { 140 + if (!config.isSimulateEnabled()) { 144 141 logger.info("--- SIMULATE mode is disabled, posts will be imported ---"); 145 142 bluesky = new BlueskyClient( 146 143 process.env.BLUESKY_USERNAME!, ··· 241 238 } 242 239 243 240 // If we are not simulating migration we create the post with the embedded media. 244 - if (!SIMULATE && bluesky) { 241 + if (!config.isSimulateEnabled() && bluesky) { 245 242 await new Promise((resolve) => 246 243 setTimeout(resolve, API_RATE_LIMIT_DELAY) 247 244 ); ··· 297 294 } 298 295 299 296 // If we are simulating the migration we want to inform the user the estimated time it may take. 300 - if (SIMULATE) { 297 + if (config.isSimulateEnabled()) { 301 298 const estimatedTime = calculateEstimatedTime(importedMedia); 302 299 logger.info(`Estimated time for real import: ${estimatedTime}`); 303 300 }