|
@@ -3,6 +3,7 @@ import * as path from 'path';
|
|
import {
|
|
import {
|
|
IgApiClient,
|
|
IgApiClient,
|
|
IgClientError, IgExactUserNotFoundError,
|
|
IgClientError, IgExactUserNotFoundError,
|
|
|
|
+ IgLoginRequiredError,
|
|
IgNetworkError,
|
|
IgNetworkError,
|
|
ReelsMediaFeedResponseItem, UserFeedResponseUser
|
|
ReelsMediaFeedResponseItem, UserFeedResponseUser
|
|
} from 'instagram-private-api';
|
|
} from 'instagram-private-api';
|
|
@@ -187,6 +188,7 @@ export default class {
|
|
}
|
|
}
|
|
return this.client.feed.reelsMedia({userIds: [userId]}).items()
|
|
return this.client.feed.reelsMedia({userIds: [userId]}).items()
|
|
.then(storyItems => {
|
|
.then(storyItems => {
|
|
|
|
+ storyItems = storyItems.map(story => ({...story, user: this.cache[userName].user}));
|
|
storyItems.forEach(item => {
|
|
storyItems.forEach(item => {
|
|
if (!(item.pk in this.cache[userName].stories)) {
|
|
if (!(item.pk in this.cache[userName].stories)) {
|
|
this.cache[userName].stories[item.pk] = item;
|
|
this.cache[userName].stories[item.pk] = item;
|
|
@@ -200,7 +202,10 @@ export default class {
|
|
.catch((error: IgClientError & Partial<RequestError>) => {
|
|
.catch((error: IgClientError & Partial<RequestError>) => {
|
|
if (error instanceof IgNetworkError) {
|
|
if (error instanceof IgNetworkError) {
|
|
logger.warn(`error on fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
|
|
logger.warn(`error on fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
|
|
- this.bot.sendTo(receiver, `获取 Fleets 时出现错误:原因: ${error.cause}`);
|
|
|
|
|
|
+ this.bot.sendTo(receiver, `获取 Fleets 时出现错误:原因: ${error.cause}`);
|
|
|
|
+ } else if (error instanceof IgLoginRequiredError) {
|
|
|
|
+ logger.warn('login required, logging in again...');
|
|
|
|
+ this.session.login().then(() => sendAllStories(rawUserName, receiver));
|
|
} else {
|
|
} else {
|
|
logger.error(`unhandled error on fetching media for ${rawUserName}: ${error}`);
|
|
logger.error(`unhandled error on fetching media for ${rawUserName}: ${error}`);
|
|
this.bot.sendTo(receiver, `获取 Fleets 时发生未知错误: ${error}`);
|
|
this.bot.sendTo(receiver, `获取 Fleets 时发生未知错误: ${error}`);
|
|
@@ -290,6 +295,9 @@ export default class {
|
|
.catch((error: IgClientError & Partial<RequestError>) => {
|
|
.catch((error: IgClientError & Partial<RequestError>) => {
|
|
if (error instanceof IgNetworkError) {
|
|
if (error instanceof IgNetworkError) {
|
|
logger.warn(`error on fetching stories for all: ${JSON.stringify(error.cause)}`);
|
|
logger.warn(`error on fetching stories for all: ${JSON.stringify(error.cause)}`);
|
|
|
|
+ } else if (error instanceof IgLoginRequiredError) {
|
|
|
|
+ logger.warn('login required, logging in again...');
|
|
|
|
+ this.session.login().then(this.workForAll);
|
|
} else {
|
|
} else {
|
|
logger.error(`unhandled error on fetching media for all: ${error}`);
|
|
logger.error(`unhandled error on fetching media for all: ${error}`);
|
|
}
|
|
}
|