Ca marche pas trop mal

This commit is contained in:
Amaury 2021-07-12 17:02:39 +02:00
parent 81f540e29d
commit 9597cddc80
5 changed files with 1301 additions and 126 deletions

View File

@ -1,13 +1,13 @@
// import { ImplementableApi } from './implementableApi'; // import { ImplementableApi } from './implementableApi';
// Api request lib // Api request lib
import fetch, { FetchError, Headers } from "node-fetch"; import fetch, { FetchError, Headers } from "node-fetch";
import { URLSearchParams } from "url"; import { URL, URLSearchParams } from "url";
import FormData from "form-data"; import FormData from "form-data";
// import dedent from "ts-dedent"; // import dedent from "ts-dedent";
namespace PeerTubeRequester { namespace PeerTubeRequester {
export type Config = { export type Config = {
domain_name: string; domain_name: string | URL;
username: string; username: string;
password: string; password: string;
}; };
@ -36,19 +36,19 @@ type UserToken = {
}; };
class PeerTubeRequester { class PeerTubeRequester {
readonly domain_name: string; readonly domain_name: URL;
readonly username: string; readonly username: string;
readonly password: string; readonly password: string;
constructor(readonly config: PeerTubeRequester.Config) { constructor(readonly config: PeerTubeRequester.Config) {
this.domain_name = config.domain_name; this.domain_name = new URL("/", config.domain_name);
this.username = config.username; this.username = config.username;
this.password = config.password; this.password = config.password;
} }
async apiRequest(message: UploadInstruction): Promise<void> { async apiRequest(message: UploadInstruction): Promise<void> {
let response = await fetch( let response = await fetch(
`${this.domain_name}/api/v1/oauth-clients/local` new URL(`/api/v1/oauth-clients/local`, this.domain_name)
); );
if (!response.ok) { if (!response.ok) {
throw new Error(response.statusText); // CRASH throw new Error(response.statusText); // CRASH
@ -67,7 +67,7 @@ class PeerTubeRequester {
let myParams = new URLSearchParams(); let myParams = new URLSearchParams();
for (const key in client_info) myParams.append(key, client_info[key]); for (const key in client_info) myParams.append(key, client_info[key]);
response = await fetch(`${this.domain_name}/api/v1/users/token`, { response = await fetch(new URL(`/api/v1/users/token`, this.domain_name), {
method: "post", method: "post",
body: myParams, body: myParams,
}); });
@ -82,11 +82,14 @@ class PeerTubeRequester {
myHeader.append("Authorization", `Bearer ${access_token}`); myHeader.append("Authorization", `Bearer ${access_token}`);
for (const key in message) myUploadForm.append(key, message[key]); for (const key in message) myUploadForm.append(key, message[key]);
response = await fetch(`${this.domain_name}/api/v1/videos/imports`, { response = await fetch(
new URL(`/api/v1/videos/imports`, this.domain_name),
{
method: "post", method: "post",
// headers: myHeader, headers: myHeader,
body: myUploadForm, body: myUploadForm,
}); }
);
if (!response.ok) { if (!response.ok) {
switch (response.status) { switch (response.status) {

1385
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
"README.md" "README.md"
], ],
"scripts": { "scripts": {
"buildAndDeploy": "npm run build && npm run deploy", "predeploy": "npm run build",
"deploy": "bash ./scripts/deploy.sh", "deploy": "bash ./scripts/deploy.sh",
"build": "tsc" "build": "tsc"
}, },
@ -33,7 +33,7 @@
"dependencies": { "dependencies": {
"@types/node-fetch": "^2.5.11", "@types/node-fetch": "^2.5.11",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator", "listener-rss-agregator": "git+https://zeteo.me/gitea/Outils-PeerTube/listener-rss-agregators#1b36afbb34",
"node-fetch": "^2.6.1" "node-fetch": "^2.6.1"
} }
} }

View File

@ -1,12 +1,13 @@
#/bin/bash
tmp_dir=$(mktemp -d)/peertube-plugin-auto-import-ytb tmp_dir=$(mktemp -d)/peertube-plugin-auto-import-ytb
work_dir=$(pwd) work_dir=$(pwd)
# echo $work_dir # echo "${work_dir}"
mkdir $tmp_dir mkdir "${tmp_dir}"
# echo "directory created" # echo "directory created"
cp "${work_dir}/dist" "${work_dir}/package.json" "${work_dir}/LICENSE" $tmp_dir -r cp "${work_dir}/dist" "${work_dir}/package.json" "${work_dir}/LICENSE" $tmp_dir -r
# echo "rsync --exclude-from=$work_dir.rsyncignore $work_dir $tmp_dir" # echo "rsync --exclude-from=$work_dir.rsyncignore $work_dir $tmp_dir"
# echo "rsync done" # echo "rsync done"
cd "../PeerTube" cd "../PeerTube-cli"
node "./dist/server/tools/peertube.js" plugins install --path "${tmp_dir}" node "./dist/server/tools/peertube.js" plugins install --path "${tmp_dir}"
# echo $tmp_dir # echo $tmp_dir

View File

@ -1,8 +1,8 @@
import { ListenerRssAggregator } from "listener-rss-agregator"; import { ListenerRssAggregator } from "listener-rss-agregator";
import { ListenerRSSInfos } from "listener-rss"; import { ListenerRss } from "listener-rss";
import { PeerTubeRequester } from "../lib/peertubeRequester"; import { PeerTubeRequester } from "../lib/peertubeRequester";
type ListenerData = ListenerRSSInfos & { type ListenerData = ListenerRss.Config & {
address: string; address: string;
channelId: string; channelId: string;
}; };
@ -38,7 +38,7 @@ async function register({
myManager = new ListenerRssAggregator(configAggregator); myManager = new ListenerRssAggregator(configAggregator);
peertube = new PeerTubeRequester({ peertube = new PeerTubeRequester({
domain_name: "localhost:9000", domain_name: "http://localhost:9000",
username: "root", username: "root",
password: "test", password: "test",
}); });