forked from cheeaun/phanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can directly link to profile and will resolve the url to agora compat…
…ible link
- Loading branch information
ghobs91
committed
Feb 29, 2024
1 parent
4dfb56f
commit 154e7e9
Showing
5 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
export const statusRegex = /\/@([^@\/]+)@?([^\/]+)?\/([^\/]+)\/?$/i; | ||
export const statusNoteRegex = /\/notes\/([^\/]+)\/?$/i; | ||
function getInstanceStatusURL(url) { | ||
// export const statusRegex = /\/@([^@\/]+)@?([^\/]+)?\/([^\/]+)\/?$/i; | ||
// export const statusNoteRegex = /\/notes\/([^\/]+)\/?$/i; | ||
|
||
const statusPostRegexes = [ | ||
/^\/@[^@\/]+\/(?:statuses|posts)\/([^\/]+)/i, // GoToSocial, Takahe | ||
/\/notes\/([^\/]+)/i, // Misskey, Firefish | ||
/^\/(?:notice|objects)\/([a-z0-9-]+)/i, // Pleroma | ||
/\/@[^@\/]+@?[^\/]+?\/([^\/]+)/i, // Mastodon | ||
]; | ||
|
||
export function getInstanceStatusObject(url) { | ||
// Regex /:username/:id, where username = @username or @username@domain, id = anything | ||
const { hostname, pathname } = new URL(url); | ||
const [, username, domain, id] = pathname.match(statusRegex) || []; | ||
|
||
if (id) { | ||
return `/${hostname}/s/${id}`; | ||
// const [, username, domain, id] = pathname.match(statusRegex) || []; | ||
for (const regex of statusPostRegexes) { | ||
const [, id] = pathname.match(regex) || []; | ||
console.log(pathname, regex, id); | ||
if (id) { | ||
return { | ||
instance: hostname, | ||
id, | ||
}; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
const [, noteId] = pathname.match(statusNoteRegex) || []; | ||
|
||
if (noteId) { | ||
return `/${hostname}/s/${noteId}`; | ||
function getInstanceStatusURL(url) { | ||
const { instance, id } = getInstanceStatusObject(url); | ||
if (instance && id) { | ||
return `/${instance}/s/${id}`; | ||
} | ||
return null; | ||
} | ||
|
||
export default getInstanceStatusURL; | ||
export default getInstanceStatusURL; |