Pārlūkot izejas kodu

support new post URL format

Mike L 3 gadi atpakaļ
vecāks
revīzija
2ac035fd3e
5 mainītis faili ar 7 papildinājumiem un 6 dzēšanām
  1. 2 2
      dist/command.js
  2. 1 1
      dist/twitter.js
  3. 1 0
      package.json
  4. 2 2
      src/command.ts
  5. 1 1
      src/twitter.ts

+ 2 - 2
dist/command.js

@@ -48,7 +48,8 @@ function sub(chat, args, reply, lock, lockfile) {
         return reply(`订阅链接格式错误:
 示例:
 https://www.instagram.com/tomoyo_kurosawa_/
-https://www.instagram.com/p/B6GHRSmgV-7/`);
+https://www.instagram.com/p/B6GHRSmgV-7/
+https://www.instagram.com/tomoyo_kurosawa_/p/B6GHRSmgV-7/`);
     }
     let offset = '0';
     const subscribeTo = (link, config = {}) => {
@@ -90,7 +91,6 @@ https://www.instagram.com/p/B6GHRSmgV-7/`);
     if (matched.postUrlSegment) {
         offset = utils_1.BigNumOps.plus(twitter_1.urlSegmentToId(matched.postUrlSegment), '-1');
         twitter_1.getPostOwner(matched.postUrlSegment).then(userName => {
-            delete matched.postUrlSegment;
             matched.userName = userName.split(':')[0];
             if (!tryFindSub(matched.userName))
                 newSub(userName);

+ 1 - 1
dist/twitter.js

@@ -24,7 +24,7 @@ const loggers_1 = require("./loggers");
 const utils_1 = require("./utils");
 const webshot_1 = require("./webshot");
 const parseLink = (link) => {
-    let match = /instagram\.com\/p\/([A-Za-z0-9\-_]+)/.exec(link);
+    let match = /instagram\.com\/(?:[^\/?#]+\/)?p\/([A-Za-z0-9\-_]+)/.exec(link);
     if (match)
         return { postUrlSegment: match[1] };
     match =

+ 1 - 0
package.json

@@ -32,6 +32,7 @@
   "dependencies": {
     "callable-instance": "^2.0.0",
     "command-line-usage": "^5.0.5",
+    "bignumber.js": "9.0.1",
     "html-entities": "^1.3.1",
     "instagram-id-to-url-segment": "github:CL-Jeremy/instagram-id-to-url-segment#built",
     "instagram-private-api": "^1.44.1",

+ 2 - 2
src/command.ts

@@ -63,7 +63,8 @@ function sub(chat: IChat, args: string[], reply: (msg: string) => any,
     return reply(`订阅链接格式错误:
 示例:
 https://www.instagram.com/tomoyo_kurosawa_/
-https://www.instagram.com/p/B6GHRSmgV-7/`);
+https://www.instagram.com/p/B6GHRSmgV-7/
+https://www.instagram.com/tomoyo_kurosawa_/p/B6GHRSmgV-7/`);
   }
   let offset = '0';
   const subscribeTo = (link: string, config: {id?: number, msg?: string} = {}) => {
@@ -99,7 +100,6 @@ https://www.instagram.com/p/B6GHRSmgV-7/`);
   if (matched.postUrlSegment) {
     offset = BigNumOps.plus(urlSegmentToId(matched.postUrlSegment), '-1');
     getPostOwner(matched.postUrlSegment).then(userName => {
-      delete matched.postUrlSegment;
       matched.userName = userName.split(':')[0];
       if (!tryFindSub(matched.userName)) newSub(userName);
     }).catch((parsedErr: Error) => {

+ 1 - 1
src/twitter.ts

@@ -23,7 +23,7 @@ import Webshot, { Cookies, Page } from './webshot';
 
 const parseLink = (link: string): { userName?: string, postUrlSegment?: string } => {
   let match =
-    /instagram\.com\/p\/([A-Za-z0-9\-_]+)/.exec(link);
+    /instagram\.com\/(?:[^\/?#]+\/)?p\/([A-Za-z0-9\-_]+)/.exec(link);
   if (match) return { postUrlSegment: match[1] };
   match =
     /instagram\.com\/([^\/?#]+)/.exec(link) ||