diff --git a/src/auth/FacebookAuth.ts b/src/auth/FacebookAuth.ts index af33161..f389494 100644 --- a/src/auth/FacebookAuth.ts +++ b/src/auth/FacebookAuth.ts @@ -1,6 +1,6 @@ import OAuth2Client from "./OAuth2Client"; -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; +import Logger from "../services/Logger"; +import Storage from "../services/Storage"; export default class FacebookAuth extends OAuth2Client { GRAPH_API_VERSION: string = "v18.0"; diff --git a/src/auth/InstagramAuth.ts b/src/auth/InstagramAuth.ts index 35ebe69..b89781b 100644 --- a/src/auth/InstagramAuth.ts +++ b/src/auth/InstagramAuth.ts @@ -1,6 +1,6 @@ import FacebookAuth from "./FacebookAuth"; -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; +import Logger from "../services/Logger"; +import Storage from "../services/Storage"; export default class InstagramAuth extends FacebookAuth { async setup() { diff --git a/src/auth/LinkedInAuth.ts b/src/auth/LinkedInAuth.ts index a7cbe07..63f0b68 100644 --- a/src/auth/LinkedInAuth.ts +++ b/src/auth/LinkedInAuth.ts @@ -1,6 +1,6 @@ import OAuth2Client from "./OAuth2Client"; -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; +import Logger from "../services/Logger"; +import Storage from "../services/Storage"; export default class LinkedInAuth extends OAuth2Client { API_VERSION = "v2"; diff --git a/src/auth/OAuth2Client.ts b/src/auth/OAuth2Client.ts index efc5813..0556f79 100644 --- a/src/auth/OAuth2Client.ts +++ b/src/auth/OAuth2Client.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import * as http from "http"; import * as url from "url"; -import Storage from "../core/Storage"; +import Storage from "../services/Storage"; class DeferredResponseQuery { promise: Promise<{ [key: string]: string | string[] }>; diff --git a/src/auth/RedditAuth.ts b/src/auth/RedditAuth.ts index 1972c6b..09998d8 100644 --- a/src/auth/RedditAuth.ts +++ b/src/auth/RedditAuth.ts @@ -1,6 +1,6 @@ import OAuth2Client from "./OAuth2Client"; -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; +import Logger from "../services/Logger"; +import Storage from "../services/Storage"; export default class RedditAuth extends OAuth2Client { API_VERSION = "v1"; diff --git a/src/auth/TwitterAuth.ts b/src/auth/TwitterAuth.ts index 0066e25..bc871b1 100644 --- a/src/auth/TwitterAuth.ts +++ b/src/auth/TwitterAuth.ts @@ -1,8 +1,8 @@ import { TwitterApi } from "twitter-api-v2"; import OAuth2Client from "./OAuth2Client"; -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; +import Logger from "../services/Logger"; +import Storage from "../services/Storage"; export default class TwitterAuth extends OAuth2Client { async setup() { diff --git a/src/cli.ts b/src/cli.ts index c848b96..dda8c75 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -3,12 +3,14 @@ Fairpost cli handler */ -import * as path from "path"; import "./bootstrap-cli"; -import Fairpost from "./core/Fairpost"; -import Logger from "./core/Logger"; -import { PostStatus } from "./core/Post"; + +import * as path from "path"; + +import Fairpost from "./services/Fairpost"; +import Logger from "./services/Logger"; import { PlatformId } from "./platforms"; +import { PostStatus } from "./models/Post"; // arguments const COMMAND = process.argv[2] ?? "help"; diff --git a/src/core/Feed.ts b/src/models/Feed.ts similarity index 99% rename from src/core/Feed.ts rename to src/models/Feed.ts index 658b0e9..847b873 100644 --- a/src/core/Feed.ts +++ b/src/models/Feed.ts @@ -1,11 +1,12 @@ import * as fs from "fs"; -import Logger from "./Logger"; -import Storage from "./Storage"; -import Platform from "./Platform"; + import Folder from "./Folder"; +import Logger from "../services/Logger"; +import Platform from "./Platform"; +import { PlatformId } from "../platforms"; import Post from "./Post"; import { PostStatus } from "./Post"; -import { PlatformId } from "../platforms"; +import Storage from "../services/Storage"; /** * Feed - the core handler of fairpost diff --git a/src/core/Folder.ts b/src/models/Folder.ts similarity index 98% rename from src/core/Folder.ts rename to src/models/Folder.ts index 111ea24..747b11f 100644 --- a/src/core/Folder.ts +++ b/src/models/Folder.ts @@ -1,6 +1,7 @@ import * as fs from "fs"; import * as path from "path"; -import Logger from "./Logger"; + +import Logger from "../services/Logger"; /** * Folder - a folder within a feed diff --git a/src/core/Platform.ts b/src/models/Platform.ts similarity index 99% rename from src/core/Platform.ts rename to src/models/Platform.ts index 121753a..df44e36 100644 --- a/src/core/Platform.ts +++ b/src/models/Platform.ts @@ -1,9 +1,10 @@ import * as fs from "fs"; -import Logger from "./Logger"; + import Folder from "./Folder"; +import Logger from "../services/Logger"; +import { PlatformId } from "../platforms"; import Post from "./Post"; import { PostStatus } from "./Post"; -import { PlatformId } from "../platforms"; /** * Platform base class to extend all platforms on diff --git a/src/core/Post.ts b/src/models/Post.ts similarity index 98% rename from src/core/Post.ts rename to src/models/Post.ts index a9e39e0..4664fe7 100644 --- a/src/core/Post.ts +++ b/src/models/Post.ts @@ -1,6 +1,7 @@ import * as fs from "fs"; -import Logger from "./Logger"; + import Folder from "./Folder"; +import Logger from "../services/Logger"; import Platform from "./Platform"; /** diff --git a/src/platforms/Ayrshare.ts b/src/platforms/Ayrshare.ts index c424f55..e08c1a6 100644 --- a/src/platforms/Ayrshare.ts +++ b/src/platforms/Ayrshare.ts @@ -1,13 +1,14 @@ -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; import * as fs from "fs"; import * as path from "path"; -import { randomUUID } from "crypto"; + +import Folder from "../models/Folder"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; import { PlatformId } from "."; -import Platform from "../core/Platform"; -import Folder from "../core/Folder"; -import Post from "../core/Post"; -import { PostStatus } from "../core/Post"; +import Post from "../models/Post"; +import { PostStatus } from "../models/Post"; +import Storage from "../services/Storage"; +import { randomUUID } from "crypto"; /** * Ayrshare base class to extend all ayrshare platforms on diff --git a/src/platforms/Ayrshare/AsFacebook.ts b/src/platforms/Ayrshare/AsFacebook.ts index d566f32..031c6ca 100644 --- a/src/platforms/Ayrshare/AsFacebook.ts +++ b/src/platforms/Ayrshare/AsFacebook.ts @@ -1,10 +1,11 @@ -import Ayrshare from "../Ayrshare"; -import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; import * as fs from "fs"; import * as sharp from "sharp"; +import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; +import { PlatformId } from ".."; +import Post from "../../models/Post"; + /** * AsFacebook: support for facebook platform through Ayrshare */ diff --git a/src/platforms/Ayrshare/AsInstagram.ts b/src/platforms/Ayrshare/AsInstagram.ts index f1ca349..d95d552 100644 --- a/src/platforms/Ayrshare/AsInstagram.ts +++ b/src/platforms/Ayrshare/AsInstagram.ts @@ -1,9 +1,10 @@ -import Logger from "../../core/Logger"; +import * as sharp from "sharp"; + import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; +import Logger from "../../services/Logger"; import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; -import * as sharp from "sharp"; +import Post from "../../models/Post"; /** * AsInstagram: support for instagram platform through Ayrshare diff --git a/src/platforms/Ayrshare/AsLinkedIn.ts b/src/platforms/Ayrshare/AsLinkedIn.ts index 47d291e..4c662b9 100644 --- a/src/platforms/Ayrshare/AsLinkedIn.ts +++ b/src/platforms/Ayrshare/AsLinkedIn.ts @@ -1,11 +1,12 @@ -import Logger from "../../core/Logger"; -import Ayrshare from "../Ayrshare"; -import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; import * as fs from "fs"; import * as sharp from "sharp"; +import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; +import Logger from "../../services/Logger"; +import { PlatformId } from ".."; +import Post from "../../models/Post"; + /** * AsLinkedIn: support for linkedin platform through Ayrshare */ diff --git a/src/platforms/Ayrshare/AsReddit.ts b/src/platforms/Ayrshare/AsReddit.ts index 5df142c..054394b 100644 --- a/src/platforms/Ayrshare/AsReddit.ts +++ b/src/platforms/Ayrshare/AsReddit.ts @@ -1,8 +1,8 @@ import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; import { PlatformId } from ".."; -import Storage from "../../core/Storage"; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; +import Post from "../../models/Post"; +import Storage from "../../services/Storage"; /** * AsReddit: support for reddit platform through Ayrshare diff --git a/src/platforms/Ayrshare/AsTikTok.ts b/src/platforms/Ayrshare/AsTikTok.ts index 6d220d9..2c571c4 100644 --- a/src/platforms/Ayrshare/AsTikTok.ts +++ b/src/platforms/Ayrshare/AsTikTok.ts @@ -1,7 +1,7 @@ import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; +import Post from "../../models/Post"; /** * AsTikTok: support for tiktok platform through Ayrshare diff --git a/src/platforms/Ayrshare/AsTwitter.ts b/src/platforms/Ayrshare/AsTwitter.ts index 9da8acb..ac307d2 100644 --- a/src/platforms/Ayrshare/AsTwitter.ts +++ b/src/platforms/Ayrshare/AsTwitter.ts @@ -1,11 +1,12 @@ -import Logger from "../../core/Logger"; -import Ayrshare from "../Ayrshare"; -import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; import * as fs from "fs"; import * as sharp from "sharp"; +import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; +import Logger from "../../services/Logger"; +import { PlatformId } from ".."; +import Post from "../../models/Post"; + /** * AsTwitter: support for twitter platform through Ayrshare */ diff --git a/src/platforms/Ayrshare/AsYouTube.ts b/src/platforms/Ayrshare/AsYouTube.ts index f7f20af..16f19ab 100644 --- a/src/platforms/Ayrshare/AsYouTube.ts +++ b/src/platforms/Ayrshare/AsYouTube.ts @@ -1,7 +1,7 @@ import Ayrshare from "../Ayrshare"; +import Folder from "../../models/Folder"; import { PlatformId } from ".."; -import Folder from "../../core/Folder"; -import Post from "../../core/Post"; +import Post from "../../models/Post"; /** * AsYouTube: support for youtube platform through Ayrshare diff --git a/src/platforms/Facebook.ts b/src/platforms/Facebook.ts index 9738396..f2918d8 100644 --- a/src/platforms/Facebook.ts +++ b/src/platforms/Facebook.ts @@ -1,15 +1,16 @@ -import Storage from "../core/Storage"; -import Logger from "../core/Logger"; -import Platform from "../core/Platform"; -import { PlatformId } from "."; -import Folder from "../core/Folder"; -import Post from "../core/Post"; -import { PostStatus } from "../core/Post"; -import FacebookAuth from "../auth/FacebookAuth"; import * as fs from "fs"; import * as path from "path"; import * as sharp from "sharp"; +import FacebookAuth from "../auth/FacebookAuth"; +import Folder from "../models/Folder"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; +import { PlatformId } from "."; +import Post from "../models/Post"; +import { PostStatus } from "../models/Post"; +import Storage from "../services/Storage"; + /** * Facebook: support for facebook platform. * diff --git a/src/platforms/Instagram.ts b/src/platforms/Instagram.ts index d79634f..e1e2e6c 100644 --- a/src/platforms/Instagram.ts +++ b/src/platforms/Instagram.ts @@ -1,15 +1,16 @@ -import Storage from "../core/Storage"; -import Logger from "../core/Logger"; -import Platform from "../core/Platform"; -import InstagramAuth from "../auth/InstagramAuth"; -import { PlatformId } from "."; -import Folder from "../core/Folder"; -import Post from "../core/Post"; -import { PostStatus } from "../core/Post"; import * as fs from "fs"; import * as path from "path"; import * as sharp from "sharp"; +import Folder from "../models/Folder"; +import InstagramAuth from "../auth/InstagramAuth"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; +import { PlatformId } from "."; +import Post from "../models/Post"; +import { PostStatus } from "../models/Post"; +import Storage from "../services/Storage"; + /** * Instagram: support for instagram platform. * diff --git a/src/platforms/LinkedIn.ts b/src/platforms/LinkedIn.ts index 90b348b..a5d0ac5 100644 --- a/src/platforms/LinkedIn.ts +++ b/src/platforms/LinkedIn.ts @@ -1,15 +1,16 @@ -import Logger from "../core/Logger"; -import Storage from "../core/Storage"; -import Platform from "../core/Platform"; -import { PlatformId } from "."; -import Folder from "../core/Folder"; -import Post from "../core/Post"; -import LinkedInAuth from "../auth/LinkedInAuth"; -import { PostStatus } from "../core/Post"; import * as fs from "fs"; //import * as path from "path"; import * as sharp from "sharp"; +import Folder from "../models/Folder"; +import LinkedInAuth from "../auth/LinkedInAuth"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; +import { PlatformId } from "."; +import Post from "../models/Post"; +import { PostStatus } from "../models/Post"; +import Storage from "../services/Storage"; + export default class LinkedIn extends Platform { id: PlatformId = PlatformId.LINKEDIN; auth: LinkedInAuth; diff --git a/src/platforms/Reddit.ts b/src/platforms/Reddit.ts index 882d16c..2dfd851 100644 --- a/src/platforms/Reddit.ts +++ b/src/platforms/Reddit.ts @@ -1,15 +1,17 @@ -import Storage from "../core/Storage"; -import Logger from "../core/Logger"; -import RedditAuth from "../auth/RedditAuth"; -import { PlatformId } from "."; -import Platform from "../core/Platform"; -import Folder from "../core/Folder"; -import Post, { PostStatus } from "../core/Post"; import * as fs from "fs"; import * as path from "path"; -import { XMLParser } from "fast-xml-parser"; import * as sharp from "sharp"; +import Post, { PostStatus } from "../models/Post"; + +import Folder from "../models/Folder"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; +import { PlatformId } from "."; +import RedditAuth from "../auth/RedditAuth"; +import Storage from "../services/Storage"; +import { XMLParser } from "fast-xml-parser"; + /** * Reddit: support for reddit platform */ diff --git a/src/platforms/Twitter.ts b/src/platforms/Twitter.ts index 1b46ecc..a10bb81 100644 --- a/src/platforms/Twitter.ts +++ b/src/platforms/Twitter.ts @@ -1,14 +1,16 @@ -import { TwitterApi } from "twitter-api-v2"; -import Storage from "../core/Storage"; -import Logger from "../core/Logger"; -import TwitterAuth from "../auth/TwitterAuth"; -import { PlatformId } from "."; -import Platform from "../core/Platform"; -import Folder from "../core/Folder"; -import Post, { PostStatus } from "../core/Post"; import * as fs from "fs"; import * as sharp from "sharp"; +import Post, { PostStatus } from "../models/Post"; + +import Folder from "../models/Folder"; +import Logger from "../services/Logger"; +import Platform from "../models/Platform"; +import { PlatformId } from "."; +import Storage from "../services/Storage"; +import { TwitterApi } from "twitter-api-v2"; +import TwitterAuth from "../auth/TwitterAuth"; + /** * Twitter: support for twitter platform */ diff --git a/src/core/Fairpost.ts b/src/services/Fairpost.ts similarity index 82% rename from src/core/Fairpost.ts rename to src/services/Fairpost.ts index 2b65923..db8080e 100644 --- a/src/core/Fairpost.ts +++ b/src/services/Fairpost.ts @@ -1,16 +1,17 @@ import * as fs from "fs"; import * as path from "path"; -import Feed from "./Feed"; -import Platform from "./Platform"; -import Storage from "./Storage"; -import Logger from "./Logger"; import * as platforms from "../platforms"; +import Feed from "../models/Feed"; +import Logger from "./Logger"; +import Platform from "../models/Platform"; +import Storage from "./Storage"; + /** * Fairpost - singleton service for fairpost app * - * - provides getFeed() - * all the fairpost logic comes from a feed + * - provides the feed, that contains + * all the fairpost logic */ class Fairpost { @@ -56,8 +57,14 @@ class Fairpost { return new Feed(this.platforms.filter((p) => p.active)); } - public fatal(msg: string) { + public error(msg: string) { + Logger.error(msg); + throw new Error(msg); + } + + public fatal(msg: string, code = 1) { Logger.fatal(msg); + process.exitCode = code; throw new Error(msg); } } diff --git a/src/core/Logger.ts b/src/services/Logger.ts similarity index 100% rename from src/core/Logger.ts rename to src/services/Logger.ts diff --git a/src/core/Storage.ts b/src/services/Storage.ts similarity index 100% rename from src/core/Storage.ts rename to src/services/Storage.ts