pupgram 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,29 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.selectFilesAction = void 0;
4
- const delay_util_1 = require("../../utils/delay.util");
7
+ const node_path_1 = __importDefault(require("node:path"));
5
8
  const error_1 = require("../../error");
6
9
  const selectFilesAction = (filePaths) => {
7
10
  return async ({ page, config, logger, defaultTimeout }) => {
8
11
  logger.info("Selecting files");
9
- const fileInputElement = (await page.waitForSelector(config.fileInputSelector, {
12
+ const fileInput = (await page.waitForSelector(config.fileInputSelector, {
10
13
  timeout: defaultTimeout,
11
14
  }));
12
- if (!fileInputElement) {
15
+ if (!fileInput) {
13
16
  throw new error_1.InstagramError("File input element not found");
14
17
  }
15
- await (0, delay_util_1.delay)(500);
16
- // logger.debug("File input element found. Making it visible")
17
- // await page.evaluate((selector) => {
18
- // const fileInputElement = document.querySelector(selector) as HTMLInputElement
19
- // fileInputElement.style.display = "block"
20
- // }, config.fileInputSelector)
21
- // logger.debug("File input element visible. Uploading files")
22
- await fileInputElement.uploadFile(...filePaths);
18
+ const absolutePaths = filePaths.map((filePath) => node_path_1.default.resolve(filePath));
19
+ try {
20
+ await fileInput.uploadFile(...absolutePaths);
21
+ logger.debug("Files uploaded via uploadFile");
22
+ }
23
+ catch (error) {
24
+ logger.error(`Failed to upload files: ${error.message}`);
25
+ throw error;
26
+ }
23
27
  logger.debug("Files selected");
24
28
  };
25
29
  };
@@ -3,25 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.waitForConfirmationAction = void 0;
4
4
  const error_1 = require("../../error");
5
5
  const waitForConfirmationAction = async ({ page, config, logger, defaultTimeout }) => {
6
- var _a;
6
+ var _a, _b;
7
7
  logger.info("Waiting for confirmation");
8
8
  let result;
9
- const configureEndpoint = "/api/v1/media/configure/";
9
+ const configureEndpoints = ["/api/v1/media/configure/", "/api/v1/media/configure_sidecar/"];
10
10
  logger.debug("Waiting for response");
11
- const response = await page.waitForResponse((res) => res.url().includes(configureEndpoint) && res.status() === 200 && res.request().method() === "POST", { timeout: 60000 * 2 });
11
+ const response = await page.waitForResponse((res) => configureEndpoints.some((endpoint) => res.url().includes(endpoint)) &&
12
+ res.status() === 200 &&
13
+ res.request().method() === "POST", { timeout: 60000 * 2 });
12
14
  const json = await response.json();
13
- if (json.status === "ok" && json.media) {
14
- const media = json.media;
15
- result = {
16
- id: media.id,
17
- pk: media.pk,
18
- code: media.code,
19
- caption: ((_a = media.caption) === null || _a === void 0 ? void 0 : _a.text) || "",
20
- };
21
- }
22
- else {
15
+ if (json.status !== "ok" || !json.media) {
23
16
  throw new error_1.InstagramError("Failed to create post");
24
17
  }
18
+ const media = json.media;
19
+ result = {
20
+ id: (_a = media.id) !== null && _a !== void 0 ? _a : media.pk,
21
+ pk: media.pk,
22
+ code: media.code,
23
+ caption: ((_b = media.caption) === null || _b === void 0 ? void 0 : _b.text) || "",
24
+ };
25
25
  logger.debug("Response received. Waiting for confirmation text message");
26
26
  await page.waitForSelector(`xpath///*[contains(text(), "${config.confirmationText}")]`, {
27
27
  timeout: defaultTimeout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pupgram",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "commonjs",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -39,7 +39,6 @@
39
39
  "typescript": "^5.9.3"
40
40
  },
41
41
  "dependencies": {
42
- "clipboardy": "^5.1.0",
43
42
  "puppeteer": "^24.36.1",
44
43
  "puppeteer-extra": "^3.3.6",
45
44
  "puppeteer-extra-plugin-stealth": "^2.11.2",