Skip to content

Commit

Permalink
feat: Divide src/core to models and services
Browse files Browse the repository at this point in the history
  • Loading branch information
pike authored and pike committed Dec 3, 2023
1 parent aebc59c commit b2435cf
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/auth/FacebookAuth.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/auth/InstagramAuth.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/auth/LinkedInAuth.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/auth/OAuth2Client.ts
Original file line number Diff line number Diff line change
@@ -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[] }>;
Expand Down
4 changes: 2 additions & 2 deletions src/auth/RedditAuth.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/auth/TwitterAuth.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import * as path from "path";
import "./bootstrap-cli";
import Fairpost from "./core/Fairpost";
import Logger from "./core/Logger";
import { PostStatus } from "./core/Post";
import Fairpost from "./services/Fairpost";
import Logger from "./services/Logger";
import { PostStatus } from "./models/Post";
import { PlatformId } from "./platforms";

// arguments
Expand Down
4 changes: 2 additions & 2 deletions src/core/Feed.ts → src/models/Feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs";
import Logger from "./Logger";
import Storage from "./Storage";
import Logger from "../services/Logger";
import Storage from "../services/Storage";
import Platform from "./Platform";
import Folder from "./Folder";
import Post from "./Post";
Expand Down
2 changes: 1 addition & 1 deletion src/core/Folder.ts → src/models/Folder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand Down
2 changes: 1 addition & 1 deletion src/core/Platform.ts → src/models/Platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import Logger from "./Logger";
import Logger from "../services/Logger";
import Folder from "./Folder";
import Post from "./Post";
import { PostStatus } from "./Post";
Expand Down
2 changes: 1 addition & 1 deletion src/core/Post.ts → src/models/Post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import Logger from "./Logger";
import Logger from "../services/Logger";
import Folder from "./Folder";
import Platform from "./Platform";

Expand Down
12 changes: 6 additions & 6 deletions src/platforms/Ayrshare.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Logger from "../core/Logger";
import Storage from "../core/Storage";
import Logger from "../services/Logger";
import Storage from "../services/Storage";
import * as fs from "fs";
import * as path from "path";
import { randomUUID } from "crypto";
import { PlatformId } from ".";
import Platform from "../core/Platform";
import Folder from "../core/Folder";
import Post from "../core/Post";
import { PostStatus } from "../core/Post";
import Platform from "../models/Platform";
import Folder from "../models/Folder";
import Post from "../models/Post";
import { PostStatus } from "../models/Post";

/**
* Ayrshare base class to extend all ayrshare platforms on
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/Ayrshare/AsFacebook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";
import * as fs from "fs";
import * as sharp from "sharp";

Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Ayrshare/AsInstagram.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Logger from "../../core/Logger";
import Logger from "../../services/Logger";
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";
import * as sharp from "sharp";

/**
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Ayrshare/AsLinkedIn.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Logger from "../../core/Logger";
import Logger from "../../services/Logger";
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";
import * as fs from "fs";
import * as sharp from "sharp";

Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Ayrshare/AsReddit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Storage from "../../core/Storage";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Storage from "../../services/Storage";
import Folder from "../../models/Folder";
import Post from "../../models/Post";

/**
* AsReddit: support for reddit platform through Ayrshare
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/Ayrshare/AsTikTok.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";

/**
* AsTikTok: support for tiktok platform through Ayrshare
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/Ayrshare/AsTwitter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Logger from "../../core/Logger";
import Logger from "../../services/Logger";
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";
import * as fs from "fs";
import * as sharp from "sharp";

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/Ayrshare/AsYouTube.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ayrshare from "../Ayrshare";
import { PlatformId } from "..";
import Folder from "../../core/Folder";
import Post from "../../core/Post";
import Folder from "../../models/Folder";
import Post from "../../models/Post";

/**
* AsYouTube: support for youtube platform through Ayrshare
Expand Down
12 changes: 6 additions & 6 deletions src/platforms/Facebook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Storage from "../core/Storage";
import Logger from "../core/Logger";
import Platform from "../core/Platform";
import Storage from "../services/Storage";
import Logger from "../services/Logger";
import Platform from "../models/Platform";
import { PlatformId } from ".";
import Folder from "../core/Folder";
import Post from "../core/Post";
import { PostStatus } from "../core/Post";
import Folder from "../models/Folder";
import Post from "../models/Post";
import { PostStatus } from "../models/Post";
import FacebookAuth from "../auth/FacebookAuth";
import * as fs from "fs";
import * as path from "path";
Expand Down
12 changes: 6 additions & 6 deletions src/platforms/Instagram.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Storage from "../core/Storage";
import Logger from "../core/Logger";
import Platform from "../core/Platform";
import Storage from "../services/Storage";
import Logger from "../services/Logger";
import Platform from "../models/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 Folder from "../models/Folder";
import Post from "../models/Post";
import { PostStatus } from "../models/Post";
import * as fs from "fs";
import * as path from "path";
import * as sharp from "sharp";
Expand Down
12 changes: 6 additions & 6 deletions src/platforms/LinkedIn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Logger from "../core/Logger";
import Storage from "../core/Storage";
import Platform from "../core/Platform";
import Logger from "../services/Logger";
import Storage from "../services/Storage";
import Platform from "../models/Platform";
import { PlatformId } from ".";
import Folder from "../core/Folder";
import Post from "../core/Post";
import Folder from "../models/Folder";
import Post from "../models/Post";
import LinkedInAuth from "../auth/LinkedInAuth";
import { PostStatus } from "../core/Post";
import { PostStatus } from "../models/Post";
import * as fs from "fs";
//import * as path from "path";
import * as sharp from "sharp";
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/Reddit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Storage from "../core/Storage";
import Logger from "../core/Logger";
import Storage from "../services/Storage";
import Logger from "../services/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 Platform from "../models/Platform";
import Folder from "../models/Folder";
import Post, { PostStatus } from "../models/Post";
import * as fs from "fs";
import * as path from "path";
import { XMLParser } from "fast-xml-parser";
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/Twitter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TwitterApi } from "twitter-api-v2";
import Storage from "../core/Storage";
import Logger from "../core/Logger";
import Storage from "../services/Storage";
import Logger from "../services/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 Platform from "../models/Platform";
import Folder from "../models/Folder";
import Post, { PostStatus } from "../models/Post";
import * as fs from "fs";
import * as sharp from "sharp";

Expand Down
16 changes: 11 additions & 5 deletions src/core/Fairpost.ts → src/services/Fairpost.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as fs from "fs";
import * as path from "path";
import Feed from "./Feed";
import Platform from "./Platform";
import Feed from "../models/Feed";
import Platform from "../models/Platform";
import Storage from "./Storage";
import Logger from "./Logger";
import * as platforms from "../platforms";

/**
* 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 {
Expand Down Expand Up @@ -56,8 +56,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);
}
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b2435cf

Please sign in to comment.