[PeerTube] Support /w/ short video links part 2
We also need to support it for comments
This commit is contained in:
parent
026751624f
commit
38ad1eaac5
|
@ -11,7 +11,6 @@ import java.util.List;
|
||||||
public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||||
|
|
||||||
private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory();
|
private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory();
|
||||||
private static final String ID_PATTERN = "/videos/(watch/)?([^/?&#]*)";
|
|
||||||
private static final String COMMENTS_ENDPOINT = "/api/v1/videos/%s/comment-threads";
|
private static final String COMMENTS_ENDPOINT = "/api/v1/videos/%s/comment-threads";
|
||||||
|
|
||||||
public static PeertubeCommentsLinkHandlerFactory getInstance() {
|
public static PeertubeCommentsLinkHandlerFactory getInstance() {
|
||||||
|
@ -20,12 +19,12 @@ public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId(String url) throws ParsingException, IllegalArgumentException {
|
public String getId(String url) throws ParsingException, IllegalArgumentException {
|
||||||
return Parser.matchGroup(ID_PATTERN, url, 2);
|
return PeertubeStreamLinkHandlerFactory.getInstance().getId(url); // the same id is needed
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onAcceptUrl(final String url) throws FoundAdException {
|
public boolean onAcceptUrl(final String url) throws FoundAdException {
|
||||||
return url.contains("/videos/");
|
return url.contains("/videos/") || url.contains("/w/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,12 +25,32 @@ public class PeertubeCommentsLinkHandlerFactoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void acceptUrlTest() throws ParsingException {
|
public void acceptUrlTest() throws ParsingException {
|
||||||
assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads?start=0&count=10&sort=-createdAt"));
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/kkGMgK9ZtnKfYAgnEtQxbv"));
|
||||||
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv"));
|
||||||
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads?start=0&count=10&sort=-createdAt"));
|
||||||
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||||
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||||
|
assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getIdFromUrl() throws ParsingException {
|
public void getIdFromUrl() throws ParsingException {
|
||||||
assertEquals("19319", linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads").getId());
|
assertEquals("kkGMgK9ZtnKfYAgnEtQxbv",
|
||||||
assertEquals("19319", linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads?start=0&count=10&sort=-createdAt").getId());
|
linkHandler.fromUrl("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv").getId());
|
||||||
|
assertEquals("kkGMgK9ZtnKfYAgnEtQxbv",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/videos/watch/kkGMgK9ZtnKfYAgnEtQxbv").getId());
|
||||||
|
assertEquals("kkGMgK9ZtnKfYAgnEtQxbv",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads").getId());
|
||||||
|
assertEquals("kkGMgK9ZtnKfYAgnEtQxbv",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads?start=0&count=10&sort=-createdAt").getId());
|
||||||
|
|
||||||
|
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||||
|
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||||
|
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads").getId());
|
||||||
|
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||||
|
linkHandler.fromUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt").getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue