|
|
@@ -1,22 +1,33 @@
|
|
|
import { refresh as refreshAirbnb } from '../airbnb/refresh-cookies';
|
|
|
import { refresh as refreshBooking } from '../booking/refresh-cookies';
|
|
|
-// import { refresh as refreshHomestay } from '../homestay/refresh-cookies'; // disabled
|
|
|
+import { refresh as refreshHomestay } from '../homestay/refresh-cookies';
|
|
|
import { handleOutput } from '../shared/api-client';
|
|
|
import { parseOutputMode } from '../shared/cookie-utils';
|
|
|
import * as path from 'path';
|
|
|
import * as os from 'os';
|
|
|
|
|
|
+// Keep in sync with services[*].disabled in config.json.
|
|
|
+// Test: tests/test_refresh_cookies.py::test_refresh_all_flags_match_config
|
|
|
+const ENABLED: Record<string, boolean> = {
|
|
|
+ airbnb: true,
|
|
|
+ booking: true,
|
|
|
+ homestay: false,
|
|
|
+};
|
|
|
+
|
|
|
const DATA_HOME = process.env.ROOM_CAL_DATA_HOME ?? path.join(os.homedir(), '.local', 'room_cal');
|
|
|
const mode = parseOutputMode(process.argv);
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
- const [airbnbCreds, bookingCreds] = await Promise.all([
|
|
|
- refreshAirbnb(mode),
|
|
|
- refreshBooking(mode),
|
|
|
+ const results = await Promise.all([
|
|
|
+ ENABLED.airbnb ? refreshAirbnb(mode) : Promise.resolve(null),
|
|
|
+ ENABLED.booking ? refreshBooking(mode) : Promise.resolve(null),
|
|
|
+ ENABLED.homestay ? refreshHomestay(mode) : Promise.resolve(null),
|
|
|
]);
|
|
|
+ const [airbnbCreds, bookingCreds, homestayCreds] = results;
|
|
|
await Promise.all([
|
|
|
- handleOutput('airbnb', airbnbCreds, mode, path.join(DATA_HOME, 'airbnb.env')),
|
|
|
- handleOutput('booking', bookingCreds, mode, path.join(DATA_HOME, 'booking.env')),
|
|
|
+ ENABLED.airbnb && handleOutput('airbnb', airbnbCreds!, mode, path.join(DATA_HOME, 'airbnb.env')),
|
|
|
+ ENABLED.booking && handleOutput('booking', bookingCreds!, mode, path.join(DATA_HOME, 'booking.env')),
|
|
|
+ ENABLED.homestay && handleOutput('homestay', homestayCreds!, mode, path.join(DATA_HOME, 'homestay.env')),
|
|
|
]);
|
|
|
if (mode !== 'stdout') console.error('\nAll credentials refreshed.');
|
|
|
}
|