-
Notifications
You must be signed in to change notification settings - Fork 20
/
Friendica.js
78 lines (69 loc) · 1.63 KB
/
Friendica.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Module, that detects a Friendica instance and returns the required values.
*
* @module Detect/Friendica
*/
import {NotSupportedError} from "/common/modules/Errors.js";
import {INTERACTION_TYPE} from "../data/INTERACTION_TYPE.js";
// https://regex101.com/r/Khzf4S/4
const REMOTE_FOLLOW_REGEX = /\/(?:dfrn_request|remote_follow)\/(.+)\/?$/;
/** The URLs to intercept and pass to this module. */
export const CATCH_URLS = new Map();
CATCH_URLS.set(REMOTE_FOLLOW_REGEX, INTERACTION_TYPE.FOLLOW);
/**
* Whether to enable replacing the previous site when redirecting or not.
*
* @private
* @type {boolean}
*/
const ENABLE_LOAD_REPLACE = false;
/**
* Determinates whether the redirect should replace the site before or not.
*
* @public
* @returns {boolean}
*/
export function shouldLoadReplace() {
return ENABLE_LOAD_REPLACE;
}
/**
* Determinates which tab should be redirected.
*
* @public
* @param {Object} requestDetails
* @returns {int}
*/
export function getTabToModify(requestDetails) {
return requestDetails.tabId;
}
/**
* Find the follow URL.
*
* @public
* @returns {Promise}
*/
export function getTootUrl() {
throw new NotSupportedError("getTootUrl() is not supported");
}
/**
* Returns the username of the given "dfrn_request" page.
*
* @private
* @function
* @param {URL} url
* @returns {string|undefined}
*/
export function getUsername(url) {
const match = REMOTE_FOLLOW_REGEX.exec(url.pathname);
return match[1];
}
/**
* Returns the server from the required URL.
*
* @function
* @param {URL} url
* @returns {string|undefined}
*/
export function getServer(url) {
return url.host;
}