Skip to content

Commit

Permalink
feat: tạo thiết lập.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ooker777 committed Dec 14, 2024
1 parent b124355 commit 4664436
Show file tree
Hide file tree
Showing 888 changed files with 153 additions and 121 deletions.
17 changes: 0 additions & 17 deletions .env
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
FIBERY_HOST = https://quacau.fibery.io
FIBERY_TOKEN = 26d174de.24b1cbf0079420149f218af264d06a5bf99
FIBERY_ARTICLE_DATABASE = Articles
FIBERY_ARTICLE_SPACE = Blog

# FACEBOOK_PROFILE_URL = "https://facebook.com/qua.cau.the.sphere"
# FACEBOOK_EMAIL = "[email protected]"
# FACEBOOK_PASSWORD = "Qu@cau00"

# FIBERY_HOST = https://torihi.fibery.io/
# FIBERY_TOKEN = 55a06407.9e13b61bec3b49dba58387602ac4c09df53
# FIBERY_ARTICLE_DATABASE = Articles
# FIBERY_ARTICLE_SPACE = Source

FACEBOOK_PROFILE_URL = "https://facebook.com/dohangminhtri511"
FACEBOOK_EMAIL = "[email protected]"
FACEBOOK_PASSWORD = "Kendykangta511@"

CHROME_PATH = "/home/runner/.cache/puppeteer/chrome/linux-131.0.6778.108/chrome-linux64/chrome",
21 changes: 21 additions & 0 deletions Thiết lập.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Fibery:
Host: https://torihi.fibery.io/
Token: 55a06407.9e13b61bec3b49dba58387602ac4c09df53
Database: Articles
Space: Source

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

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

# Facebook:
Profile url: https://facebook.com/qua.cau.the.sphere
Email: [email protected]
Password: Qu@cau00
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@std/fs": "jsr:@std/fs@^1.0.6",
"@std/log": "jsr:@std/log@^0.224.11",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"linkedom": "npm:linkedom@^0.18.5",
"mdast": "npm:mdast@^3.0.0",
"mdast-util-from-markdown": "npm:mdast-util-from-markdown@^2.0.2",
Expand Down
5 changes: 5 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { truyVấnFibery, tảiBàiVàẢnh } from "./scr/1. Kéo bài/Fibery.ts
import { mởTrìnhDuyệt } from "./scr/Code hỗ trợ/Trình duyệt, cookie.ts";
import { đăngLênFacebook } from "./scr/2. Đăng bài/Trang chủ Facebook.ts";

const debug = false;
// const debug = true;
// const debug = false;
const debug = true;

async function kéoBàiTừCácNguồn() {
log.info("Kéo bài từ các nguồn");
Expand All @@ -33,6 +33,9 @@ try {
case "TargetCloseError":
console.error(name);
break;
case "TimeoutError":
log.error(name);
throw "";

default:
log.error(name);
Expand Down
10 changes: 4 additions & 6 deletions scr/1. Kéo bài/Fibery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as log from "@std/log";
import { resolve } from "@std/path/resolve";
import { lấyEnv, NƠI_LƯU } from "../Code hỗ trợ/env và hằng.ts";
import { NƠI_LƯU, thiếtLập } 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 FIBERY_HOST = lấyEnv("FIBERY_HOST");
const FIBERY_ARTICLE_DATABASE = lấyEnv("FIBERY_ARTICLE_DATABASE");
const FIBERY_ARTICLE_SPACE = lấyEnv("FIBERY_ARTICLE_SPACE");
const fiberyEndPoint = `${FIBERY_HOST}/api/graphql/space/${FIBERY_ARTICLE_SPACE}`;
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");
Expand All @@ -20,7 +18,7 @@ export async function truyVấnFibery(): Promise<BàiTrênFibery[] | never[]> {
log.error(`Phản hồi từ Fibery: "${kếtQuả.message}"`);
return [];
}
return kếtQuả.data[`find${FIBERY_ARTICLE_DATABASE}`];
return kếtQuả.data[`find${database}`];
}

async function tảiTấtCảẢnh(md: string) {
Expand Down
22 changes: 11 additions & 11 deletions scr/2. Đăng bài/Trang chủ Facebook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as log from "@std/log";
import { Browser, Page } from "puppeteer";
import { lấyEnv } from "../Code hỗ trợ/env và hằng.ts";
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) {
Expand All @@ -10,14 +10,14 @@ async function login(page: Page) {
if (cầnLogin) {
console.info("Đăng nhập vào Facebook");

const email = lấyEnv("FACEBOOK_EMAIL");
const password = lấyEnv("FACEBOOK_PASSWORD");
const { Email: email, Password: password } = thiếtLập.Facebook;

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

async function tạoBàiViết(page: Page, đườngDẫnTớiBài: string) {
Expand All @@ -26,6 +26,7 @@ async function tạoBàiViết(page: Page, đườngDẫnTớiBài: string) {
await page.locator("::-p-text(What's on your mind)").click();
console.info("Gõ văn bản");
await page.keyboard.type(text);
await page.waitForNavigation({ waitUntil: "networkidle2" });
}

async function đăngẢnh(page: Page, imagePaths: (string | undefined)[]) {
Expand All @@ -35,6 +36,7 @@ async function đăngẢnh(page: Page, imagePaths: (string | undefined)[]) {
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]!);
}
await page.waitForNavigation({ waitUntil: "networkidle2" });
}
async function chọnTrangĐểĐăngCùng(page: Page) {
console.info("Bấm next");
Expand All @@ -44,18 +46,15 @@ async function chọnTrangĐểĐăngCùng(page: Page) {

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

export async function đăngLênFacebook(đườngDẫnTớiBài: string | undefined, dsĐườngDẫnTớiẢnh: Array<string | undefined>, trìnhDuyệt: Browser) {
log.info("Đăng lên Facebook");

const url = "https://facebook.com/";
const page = await mởTrangMới(url, trìnhDuyệt);
const page = await mởTrangMới("https://facebook.com/", trìnhDuyệt);

await login(page);
const html = await page.content();
console.log("🚀 ~ đăngLênFacebook ~ html:", html);
const cầnXácThực2Lớp = await page.$("::-p-text(verify)");
const cầnXácThực2Lớp = page.url().includes("two_step_verification");
if (cầnXácThực2Lớp) {
log.warn("Bị yêu cầu phải xác thực 2 lớp");
} else if (đườngDẫnTớiBài) {
Expand All @@ -67,8 +66,9 @@ export async function đăngLênFacebook(đườngDẫnTớiBài: string | undef
await ghiCookie(page);
} catch (error) {
const { name } = error as Error;
if (name === "TimeoutError") throw name;
if (name === "TimeoutError") throw error;
console.error(name);
}
} else console.info("Không có bài nào. Bỏ qua phần đăng bài");
} else log.warn("Không có bài nào. Bỏ qua phần đăng bài");
await page.waitForNavigation({ waitUntil: "networkidle2" });
}
9 changes: 4 additions & 5 deletions scr/Code hỗ trợ/Fibery/Code hỗ trợ cho Fibery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Image } from "mdast";
import * as log from "@std/log";
import { visit } from "unist-util-visit";
import { resolve } from "@std/path/resolve";
import { lấyEnv, NƠI_LƯU } from "../env và hằng.ts";
import { NƠI_LƯU, thiếtLập } from "../env và hằng.ts";
import { fromMarkdown } from "mdast-util-from-markdown";
import { Destination, download } from "download";

export async function tạoQueryBody(path: string) {
return JSON.stringify({ query: await Deno.readTextFile(path) }, null, 2);
}

const { Host: host, Token: token } = thiếtLập.Fibery;
export function header(): HeadersInit | undefined {
const FIBERY_TOKEN = lấyEnv("FIBERY_TOKEN");
return {
"Content-Type": `application/json`,
Authorization: `Token ${FIBERY_TOKEN}`,
Authorization: `Token ${token}`,
};
}

Expand All @@ -30,8 +30,7 @@ export function dsNodeẢnh(md: BàiTrênFibery["content"]["md"]) {
}

export async function tảiẢnh(imageNode: Image) {
const FIBERY_HOST = lấyEnv("FIBERY_HOST");
const url = `${FIBERY_HOST}${imageNode.url}`;
const url = `${host}${imageNode.url}`;
try {
const tênẢnh = imageNode.alt;
const nơiLưu: Destination = {
Expand Down
33 changes: 24 additions & 9 deletions scr/Code hỗ trợ/Trình duyệt, cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,30 @@ export async function đọcCookie(page: Page) {

export async function mởTrìnhDuyệt(debug = false) {
log.info("Mở trình duyệt");
const thiếtLậpTrìnhDuyệt = {
// executablePath: "C:/Users/ganuo/.cache/puppeteer/chrome/win64-125.0.6422.60/chrome-win64/chrome.exe",
executablePath: "/home/runner/.cache/puppeteer/chrome/linux-131.0.6778.108/chrome-linux64/chrome",
headless: !debug,
userDataDir: "./user_data",
devtools: debug,
// dumpio: true,
args: minimal_args.concat(args),
};

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,
// dumpio: true,
args: minimal_args.concat(args),
};
break;

default:
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",
// dumpio: true,
args: minimal_args.concat(args),
};
break;
}

return await puppeteer.launch(thiếtLậpTrìnhDuyệt);
}
Expand Down
21 changes: 16 additions & 5 deletions scr/Code hỗ trợ/env và hằng.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import "jsr:@std/dotenv/load";
import { parse } from "@std/yaml";

export function lấyEnv(key: string): string {
const value = Deno.env.get(key);
if (!value) throw new Error(`${key} không được thiết lập trong env`);
return value;
interface ThiếtLập {
Fibery: {
Host: string;
Token: string;
Database: string;
Space: string;
};
Facebook: {
"Profile url": string;
Email: string;
Password: string;
};
}

export const thiếtLập = parse(await Deno.readTextFile("./Thiết lập.yaml")) as ThiếtLập;

export const NƠI_LƯU = "Bài viết";
export const ĐƯỜNG_DẪN_TỚI_COOKIE = "cookies.json";
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.
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.
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 removed user_data/Default/Cache/Cache_Data/285bbb11adf36466_0
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.
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.
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.
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.
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.
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.
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.
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.
Loading

0 comments on commit 4664436

Please sign in to comment.