Skip to content

Commit

Permalink
refactor: báo lỗi và trạng thái tốt hơn
Browse files Browse the repository at this point in the history
  • Loading branch information
ooker777 committed Dec 16, 2024
1 parent 4664436 commit fae4a03
Show file tree
Hide file tree
Showing 1,477 changed files with 320 additions and 388 deletions.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# user_data
draft
# .env
.env
node_modules
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"deno.lint": true,
"editor.formatOnSave": true,
// "editor.formatOnSave": false,
"deno.config": "./deno.json",
"editor.defaultFormatter": "denoland.vscode-deno",
"[typescriptreact]": {
"editor.defaultFormatter": "denoland.vscode-deno"
Expand Down
4 changes: 2 additions & 2 deletions scr/1. Kéo bài/Fibery.ts → 1. Kéo bài/Fibery.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as log from "@std/log";
import { resolve } from "@std/path/resolve";
import { NƠI_LƯU, thiếtLập } from "../Code hỗ trợ/env và hằng.ts";
import { NƠI_LƯU, thiếtLập, ĐƯỜNG_DẪN_TỚI_QUERY_FIBERY } from "../Code hỗ trợ/env và hằng.ts";
import { BàiTrênFibery, dsNodeẢnh, header, tạoQueryBody, tảiẢnh } from "../Code hỗ trợ/Fibery/Code hỗ trợ cho Fibery.ts";

export async function truyVấnFibery(): Promise<BàiTrênFibery[] | never[]> {
const { Host: host, Database: database, Space: space } = thiếtLập.Fibery;
const fiberyEndPoint = `${host}/api/graphql/space/${space}`;

log.info("Lấy dữ liệu trên Fibery");
const queryBody = await tạoQueryBody("scr/Code hỗ trợ/Fibery/query.graphql");
const queryBody = await tạoQueryBody(ĐƯỜNG_DẪN_TỚI_QUERY_FIBERY);
const kếtQuả = await (await fetch(fiberyEndPoint, {
method: "POST",
body: queryBody,
Expand Down
82 changes: 82 additions & 0 deletions 2. Đăng bài/Trang chủ Facebook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Browser, Page } from "puppeteer";
import { thiếtLập } from "../Code hỗ trợ/env và hằng.ts";
import { ghiCookie, mởTrangMới } from "../Code hỗ trợ/Trình duyệt, cookie.ts";

async function login(page: Page) {
const loginSelector = "::-p-text(login)";
const cầnLogin = await page.$(loginSelector);

if (cầnLogin) {
const { Email: email, Password: password } = thiếtLập.Facebook;
console.info(`Đăng nhập vào Facebook bằng email ${email}`);

await page.keyboard.type(email);
page.keyboard.press("Tab");
await page.keyboard.type(password);
page.keyboard.press("Enter");
await page.waitForNavigation();
}
}

async function xácThực2lớp(page: Page) {
let cầnXácThực2Lớp = page.url().includes("two_step_verification");

if (cầnXácThực2Lớp) {
console.warn("Bị yêu cầu phải xác thực 2 lớp. Chờ xác thực");
await page.waitForNavigation();
cầnXácThực2Lớp = page.url().includes("two_step_verification");
await xácThực2lớp(page);
}
}

const selector = "::-p-text(What's on your mind)";
const nextButtonSelector = '*[aria-label="Next"][role="button"]';
const selectorẢnh = '*[aria-label="Photo/video"][role="button"]';

async function tạoBàiViết(page: Page, đườngDẫnTớiBài: string) {
console.info("Mở ô nhập bài");
await page.locator(selector).click();
await page.waitForSelector(selectorẢnh);

const text = await Deno.readTextFile(đườngDẫnTớiBài);
console.info(`Gõ ${text.length} ký tự`);
await page.keyboard.type(text);
console.info("Đã gõ xong");
}

async function đăngẢnh(page: Page, imagePaths: (string | undefined)[]) {
if (imagePaths.length > 0) {
console.info("Chọn nút ảnh");
await page.locator(selectorẢnh).click();
const inputElement = await page.$('input[accept="image/*,image/heif,image/heic,video/*,video/mp4,video/x-m4v,video/x-matroska,.mkv"]');
await inputElement?.uploadFile(imagePaths[0]!);
}
}
async function chọnTrangĐểĐăngCùng(page: Page) {
console.info("Bấm next");
// await (await page.$(nextButtonSelector))!.click();
await page.locator(nextButtonSelector).click();

console.info("Bấm post");
await page.locator('*[aria-label="Post"][role="button"]').click();
}

export async function đăngLênFacebook(đườngDẫnTớiBài: string | undefined, dsĐườngDẫnTớiẢnh: Array<string | undefined>, trìnhDuyệt: Browser) {
const page = await mởTrangMới("https://facebook.com/", trìnhDuyệt);
await login(page);
await xácThực2lớp(page);

if (đườngDẫnTớiBài) {
try {
await tạoBàiViết(page, đườngDẫnTớiBài);
await đăngẢnh(page, dsĐườngDẫnTớiẢnh);
await chọnTrangĐểĐăngCùng(page);
console.info("Đã đăng lên Facebook");
await ghiCookie(page);
} catch (error) {
const { name } = error as Error;
if (name === "TimeoutError") throw error;
console.error(name);
}
} else console.warn("Không có bài nào. Bỏ qua phần đăng bài");
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as log from "@std/log";
import puppeteer, { Browser, Page } from "puppeteer";
import { ĐƯỜNG_DẪN_TỚI_COOKIE } from "./env và hằng.ts";
import { flags, ĐƯỜNG_DẪN_TỚI_COOKIE, ĐƯỜNG_DẪN_TỚI_DỮ_LIỆU_NGƯỜI_DÙNG } from "./env và hằng.ts";

const args = ["--window-size=1920,1080"];
export const minimal_args = [
Expand Down Expand Up @@ -60,22 +60,23 @@ export async function đọcCookie(page: Page) {
console.log("Chưa có cookie");
} else {
log.error("Có lỗi khi nạp cookie");
console.error(error.message);
console.error((error as Error).message);
}
}
}

export async function mởTrìnhDuyệt(debug = false) {
log.info("Mở trình duyệt");
export async function mởTrìnhDuyệt() {
const headful = flags.headful;
log.info(`Mở trình duyệt chế độ ${headful ? "headful" : "headless"}`);

let thiếtLậpTrìnhDuyệt;
switch (Deno.build.os) {
case "windows":
thiếtLậpTrìnhDuyệt = {
executablePath: "C:/Users/ganuo/.cache/puppeteer/chrome/win64-125.0.6422.60/chrome-win64/chrome.exe",
headless: !debug,
userDataDir: "./user_data",
devtools: debug,
headless: !headful,
userDataDir: ĐƯỜNG_DẪN_TỚI_DỮ_LIỆU_NGƯỜI_DÙNG,
devtools: headful,
// dumpio: true,
args: minimal_args.concat(args),
};
Expand All @@ -85,7 +86,7 @@ export async function mởTrìnhDuyệt(debug = false) {
log.info("Linux");
thiếtLậpTrìnhDuyệt = {
executablePath: "/home/runner/.cache/puppeteer/chrome/linux-131.0.6778.108/chrome-linux64/chrome",
userDataDir: "./user_data",
userDataDir: ĐƯỜNG_DẪN_TỚI_DỮ_LIỆU_NGƯỜI_DÙNG,
// dumpio: true,
args: minimal_args.concat(args),
};
Expand Down
31 changes: 31 additions & 0 deletions Code hỗ trợ/env và hằng.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { parseAll } from "@std/yaml";
import { resolve } from "@std/path/resolve";
import { parseArgs } from "@std/cli/parse-args";

interface ThiếtLập {
Fibery: {
Host: string;
Token: string;
Database: string;
Space: string;
};
Facebook: {
"Profile url": string;
Email: string;
Password: string;
};
}
export const flags = parseArgs(Deno.args, {
boolean: ["headful"],
string: ["email"],
default: { headful: false, email: "[email protected]" },
});

const dsThiếtLập = parseAll(await Deno.readTextFile("./Thiết lập.yaml"), { schema: "core" }) as ThiếtLập[];
export const thiếtLập = dsThiếtLập.find((thiếtLập) => thiếtLập.Facebook.Email === flags.email) || dsThiếtLập[0];

export const NƠI_LƯU = "Bài viết";
export const ĐƯỜNG_DẪN_TỚI_XÁC_THỰC_ĐĂNG_NHẬP = "Xác thực đăng nhập";
export const ĐƯỜNG_DẪN_TỚI_COOKIE = resolve(ĐƯỜNG_DẪN_TỚI_XÁC_THỰC_ĐĂNG_NHẬP, "Cookie", `${flags.email}.json`);
export const ĐƯỜNG_DẪN_TỚI_DỮ_LIỆU_NGƯỜI_DÙNG = resolve(ĐƯỜNG_DẪN_TỚI_XÁC_THỰC_ĐĂNG_NHẬP, "Dữ liệu người dùng", `${flags.email}`);
export const ĐƯỜNG_DẪN_TỚI_QUERY_FIBERY = resolve("Code hỗ trợ", "Fibery", "query.graphql");
19 changes: 10 additions & 9 deletions Thiết lập.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ Fibery:
Space: Source

Facebook:
# Profile url: https://facebook.com/dohangminhtri511
# Email: [email protected]
# Password: Kendykangta511@
Profile url: https://facebook.com/dohangminhtri511
Email: [email protected]
Password: Kendykangta511@

# Fibery:
# Host: https://quacau.fibery.io
# Token: 26d174de.24b1cbf0079420149f218af264d06a5bf99
# Database: Articles
# Space: Blog
---
Fibery:
Host: https://quacau.fibery.io
Token: 26d174de.24b1cbf0079420149f218af264d06a5bf99
Database: Articles
Space: Blog

# Facebook:
Facebook:
Profile url: https://facebook.com/qua.cau.the.sphere
Email: [email protected]
Password: Qu@cau00
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2024/12/17-00:40:45.554 21e0 Creating DB D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension Rules since it was missing.
2024/12/17-00:40:45.618 21e0 Reusing MANIFEST D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension Rules/MANIFEST-000001
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2024/12/17-00:40:45.623 21e0 Creating DB D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension Scripts since it was missing.
2024/12/17-00:40:45.640 21e0 Reusing MANIFEST D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension Scripts/MANIFEST-000001
Binary file not shown.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2024/12/17-00:40:46.119 4ed4 Creating DB D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension State since it was missing.
2024/12/17-00:40:46.223 4ed4 Reusing MANIFEST D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension State/MANIFEST-000001
2024/12/17-00:40:46.225 4ed4 Recovering log #3
2024/12/17-00:40:46.254 4ed4 Reusing old log D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension State/000003.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2024/12/17-00:29:52.656 4628 Reusing MANIFEST D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension State/MANIFEST-000001
2024/12/17-00:29:52.661 4628 Recovering log #3
2024/12/17-00:29:52.662 4628 Reusing old log D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Extension State/000003.log
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2024/12/17-00:40:45.653 2494 Creating DB D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Local Storage\leveldb since it was missing.
2024/12/17-00:40:45.695 2494 Reusing MANIFEST D:\QC supplements\Code\Apps\Xây nhân hiệu tự động\Xác thực đăng nhập\Dữ liệu người dùng\[email protected]\Default\Local Storage\leveldb/MANIFEST-000001
File renamed without changes.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"net":{"network_qualities":{"CAASABiAgICA+P////8B":"4G"}}}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"sts":[{"expiry":1749922856.424933,"host":"TZmujbl93Yt3JI8wZ4X/zjkA0WFNGNW44A+o7h4YyHw=","mode":"force-https","sts_include_subdomains":false,"sts_observed":1734370856.424937},{"expiry":1749922849.403079,"host":"7QzmF0xxCtHTEKYxqWspZY5pl1F0B90+PraFnPulnH8=","mode":"force-https","sts_include_subdomains":true,"sts_observed":1734370849.403095},{"expiry":1765906846.675307,"host":"8/RrMmQlCD2Gsp14wUCE1P8r7B2C5+yE0+g79IPyRsc=","mode":"force-https","sts_include_subdomains":true,"sts_observed":1734370846.675314}],"version":2}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"account_tracker_service_last_update":"13378844445954327","alternate_error_pages":{"backup":true},"apps":{"shortcuts_arch":"","shortcuts_version":0},"autocomplete":{"retention_policy_last_version":125},"autofill":{"last_version_deduped":125},"browser":{"has_seen_welcome_page":false},"commerce_daily_metrics_last_update_time":"13378844445929020","countryid_at_install":22094,"domain_diversity":{"last_reporting_timestamp":"13378844445957942"},"enterprise_profile_guid":"9fa33eb3-7425-439d-bd2e-03912f95a4c1","extensions":{"alerts":{"initialized":true},"chrome_url_overrides":{},"last_chrome_version":"125.0.6422.60"},"gaia_cookie":{"changed_time":1734370846.678622,"hash":"2jmj7l5rSw0yVb/vlWAYkK/YBwk=","last_list_accounts_data":"[\"gaia.l.a.r\",[]]"},"gcm":{"product_category_for_subtypes":"com.googlechromefortesting.windows"},"google":{"services":{"signin_scoped_device_id":"3ddaa17d-903b-48b5-9bcd-09e00782238a"}},"intl":{"selected_languages":"en-US,en"},"invalidation":{"per_sender_topics_to_handler":{"1013309121859":{}}},"media":{"engagement":{"schema_version":5}},"ntp":{"num_personal_suggestions":2},"privacy_sandbox":{"first_party_sets_data_access_allowed_initialized":true,"first_party_sets_enabled":false},"profile":{"avatar_index":26,"background_password_check":{"check_fri_weight":9,"check_interval":"2592000000000","check_mon_weight":8,"check_sat_weight":6,"check_sun_weight":6,"check_thu_weight":9,"check_tue_weight":9,"check_wed_weight":9,"next_check_time":"13381498377780073"},"content_settings":{"did_migrate_adaptive_notification_quieting_to_cpss":true,"disable_quiet_permission_ui_time":{"notifications":"13378844445404554"},"enable_cpss":{"notifications":true},"enable_quiet_permission_ui":{"notifications":false},"exceptions":{"3pcd_heuristics_grants":{},"3pcd_support":{},"abusive_notification_permissions":{},"access_to_get_all_screens_media_in_session":{},"accessibility_events":{},"anti_abuse":{},"app_banner":{"https://www.facebook.com:443,*":{"last_modified":"13378844450363425","setting":{"https://www.facebook.com/":{"next_install_text_animation":{"delay":"86400000000","last_shown":"13378844450361833"}},"https://www.facebook.com/?ref=homescreenpwa":{"couldShowBannerEvents":1.3378844450363398e+16}}}},"ar":{},"auto_picture_in_picture":{},"auto_select_certificate":{},"automatic_downloads":{},"automatic_fullscreen":{},"autoplay":{},"background_sync":{},"bluetooth_chooser_data":{},"bluetooth_guard":{},"bluetooth_scanning":{},"camera_pan_tilt_zoom":{},"captured_surface_control":{},"client_hints":{"https://www.facebook.com:443,*":{"last_modified":"13378844454833362","setting":{"client_hints":[1,3,11,14,15,23]}}},"clipboard":{},"cookie_controls_metadata":{"https://[*.]facebook.com,*":{"last_modified":"13378844454863196","setting":{}}},"cookies":{},"direct_sockets":{},"durable_storage":{},"fedcm_idp_registration":{},"fedcm_idp_signin":{"https://accounts.google.com:443,*":{"last_modified":"13378844446679515","setting":{"chosen-objects":[{"idp-origin":"https://accounts.google.com","idp-signin-status":false}]}}},"fedcm_share":{},"file_system_access_chooser_data":{},"file_system_access_extended_permission":{},"file_system_access_restore_permission":{},"file_system_last_picked_directory":{},"file_system_read_guard":{},"file_system_write_guard":{},"formfill_metadata":{"https://www.facebook.com:443,*":{"last_modified":"13378844451090404","setting":{"UserDataFieldFilled":true}}},"geolocation":{},"hid_chooser_data":{},"hid_guard":{},"http_allowed":{},"https_enforced":{},"idle_detection":{},"images":{},"important_site_info":{},"insecure_private_network":{},"intent_picker_auto_display":{},"javascript":{},"javascript_jit":{},"keyboard_lock":{},"legacy_cookie_access":{},"local_fonts":{},"media_engagement":{},"media_stream_camera":{},"media_stream_mic":{},"midi_sysex":{},"mixed_script":{},"nfc_devices":{},"notification_interactions":{},"notification_permission_review":{},"notifications":{},"password_protection":{},"payment_handler":{},"permission_autoblocking_data":{},"permission_autorevocation_data":{},"pointer_lock":{},"popups":{},"private_network_chooser_data":{},"private_network_guard":{},"protected_media_identifier":{},"protocol_handler":{},"reduced_accept_language":{},"safe_browsing_url_check_data":{},"sensors":{},"serial_chooser_data":{},"serial_guard":{},"site_engagement":{"https://www.facebook.com:443,*":{"last_modified":"13378844448852696","setting":{"lastEngagementTime":1.3378844448852662e+16,"lastShortcutLaunchTime":0.0,"pointsAddedToday":3.0,"rawScore":3.0}}},"sound":{},"speaker_selection":{},"ssl_cert_decisions":{},"storage_access":{},"subresource_filter":{},"subresource_filter_data":{},"third_party_storage_partitioning":{},"top_level_3pcd_origin_trial":{},"top_level_3pcd_support":{},"top_level_storage_access":{},"tracking_protection":{},"unused_site_permissions":{},"usb_chooser_data":{},"usb_guard":{},"vr":{},"webid_api":{},"webid_auto_reauthn":{},"window_placement":{}},"pref_version":1},"created_by_version":"125.0.6422.60","creation_time":"13378843509574741","exit_type":"Crashed","last_engagement_time":"13378844448852662","managed":{"banner_state":1,"locally_parent_approved_extensions":{}},"managed_user_id":"","name":"Person 1","password_account_storage_settings":{},"password_hash_data_list":[]},"safebrowsing":{"event_timestamps":{},"metrics_last_log_time":"13378844445"},"segmentation_platform":{"uma_in_sql_start_time":"13378844445387974"},"sessions":{"event_log":[{"crashed":false,"time":"13378844445382845","type":0}],"session_data_status":1},"settings":{"a11y":{"apply_page_colors_only_on_increased_contrast":true}},"signin":{"allowed":true},"spellcheck":{"dictionaries":["en-US"]},"sync":{"autofill_wallet_import_enabled_migrated":true},"tracking_protection":{"tracking_protection_3pcd_enabled":false},"translate_site_blacklist":[],"translate_site_blocklist_with_time":{},"web_apps":{"daily_metrics":{"https://www.facebook.com/?ref=homescreenpwa":{"background_duration_sec":0,"captures_links":false,"effective_display_mode":2,"foreground_duration_sec":0,"installed":false,"num_sessions":0,"promotable":true}},"daily_metrics_date":"13378842000000000","did_migrate_default_chrome_apps":["MigrateDefaultChromeAppToWebAppsGSuite","MigrateDefaultChromeAppToWebAppsNonGSuite"],"last_preinstall_synchronize_version":"125"}}
File renamed without changes.
Binary file not shown.
Loading

0 comments on commit fae4a03

Please sign in to comment.