forked from Outils-PeerTube/peertube-plugin-auto-import-ytb
Ca marche pas trop mal
This commit is contained in:
parent
81f540e29d
commit
9597cddc80
|
@ -1,13 +1,13 @@
|
|||
// import { ImplementableApi } from './implementableApi';
|
||||
// Api request lib
|
||||
import fetch, { FetchError, Headers } from "node-fetch";
|
||||
import { URLSearchParams } from "url";
|
||||
import { URL, URLSearchParams } from "url";
|
||||
import FormData from "form-data";
|
||||
// import dedent from "ts-dedent";
|
||||
|
||||
namespace PeerTubeRequester {
|
||||
export type Config = {
|
||||
domain_name: string;
|
||||
domain_name: string | URL;
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
|
@ -36,19 +36,19 @@ type UserToken = {
|
|||
};
|
||||
|
||||
class PeerTubeRequester {
|
||||
readonly domain_name: string;
|
||||
readonly domain_name: URL;
|
||||
readonly username: string;
|
||||
readonly password: string;
|
||||
|
||||
constructor(readonly config: PeerTubeRequester.Config) {
|
||||
this.domain_name = config.domain_name;
|
||||
this.domain_name = new URL("/", config.domain_name);
|
||||
this.username = config.username;
|
||||
this.password = config.password;
|
||||
}
|
||||
|
||||
async apiRequest(message: UploadInstruction): Promise<void> {
|
||||
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) {
|
||||
throw new Error(response.statusText); // CRASH
|
||||
|
@ -67,7 +67,7 @@ class PeerTubeRequester {
|
|||
let myParams = new URLSearchParams();
|
||||
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",
|
||||
body: myParams,
|
||||
});
|
||||
|
@ -82,11 +82,14 @@ class PeerTubeRequester {
|
|||
myHeader.append("Authorization", `Bearer ${access_token}`);
|
||||
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",
|
||||
// headers: myHeader,
|
||||
headers: myHeader,
|
||||
body: myUploadForm,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
switch (response.status) {
|
||||
|
|
1385
package-lock.json
generated
1385
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -24,7 +24,7 @@
|
|||
"README.md"
|
||||
],
|
||||
"scripts": {
|
||||
"buildAndDeploy": "npm run build && npm run deploy",
|
||||
"predeploy": "npm run build",
|
||||
"deploy": "bash ./scripts/deploy.sh",
|
||||
"build": "tsc"
|
||||
},
|
||||
|
@ -33,7 +33,7 @@
|
|||
"dependencies": {
|
||||
"@types/node-fetch": "^2.5.11",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#/bin/bash
|
||||
tmp_dir=$(mktemp -d)/peertube-plugin-auto-import-ytb
|
||||
work_dir=$(pwd)
|
||||
# echo $work_dir
|
||||
# echo "${work_dir}"
|
||||
|
||||
mkdir $tmp_dir
|
||||
mkdir "${tmp_dir}"
|
||||
# echo "directory created"
|
||||
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 done"
|
||||
cd "../PeerTube"
|
||||
cd "../PeerTube-cli"
|
||||
node "./dist/server/tools/peertube.js" plugins install --path "${tmp_dir}"
|
||||
# echo $tmp_dir
|
|
@ -1,8 +1,8 @@
|
|||
import { ListenerRssAggregator } from "listener-rss-agregator";
|
||||
import { ListenerRSSInfos } from "listener-rss";
|
||||
import { ListenerRss } from "listener-rss";
|
||||
import { PeerTubeRequester } from "../lib/peertubeRequester";
|
||||
|
||||
type ListenerData = ListenerRSSInfos & {
|
||||
type ListenerData = ListenerRss.Config & {
|
||||
address: string;
|
||||
channelId: string;
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ async function register({
|
|||
myManager = new ListenerRssAggregator(configAggregator);
|
||||
|
||||
peertube = new PeerTubeRequester({
|
||||
domain_name: "localhost:9000",
|
||||
domain_name: "http://localhost:9000",
|
||||
username: "root",
|
||||
password: "test",
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user