From d0c1f45bc917d6ca4a881e8198439675aca4144b Mon Sep 17 00:00:00 2001 From: CaramelKat <32065563+caramelkat@users.noreply.github.com> Date: Mon, 6 Sep 2021 03:18:23 -0500 Subject: [PATCH] Updated POST model --- package-lock.json | 32 +- package.json | 2 +- src/config.json | 12 +- src/database.js | 12 +- src/html/portal/communities.html | 4 +- src/html/portal/communities_body.html | 1 - src/html/portal/settings_body.html | 10 +- src/html/portal/user.html | 278 ++++++++++++++++++ src/html/portal/user_body.html | 31 +- src/models/communities.js | 26 ++ src/models/post.js | 20 +- src/models/user.js | 249 +++++++++++++++- src/server.js | 2 - src/services/miiverse-api/index.js | 1 + .../miiverse-api/routes/communities.js | 16 + src/services/miiverse-api/routes/index.js | 1 + .../miiverse-api/routes/policyLists.js | 92 ++++++ src/services/miiverse-api/routes/post.js | 9 +- src/services/web-api/index.js | 35 --- src/services/web-api/routes/communities.js | 91 ------ src/services/web-api/routes/ctr.js | 12 - src/services/web-api/routes/index.js | 9 - src/services/web-api/routes/newPost.js | 104 ------- src/services/web-api/routes/portal.js | 248 ---------------- src/services/web-api/routes/post.js | 148 ---------- src/services/web-api/routes/users.js | 61 ---- src/services/web-api/routes/web.js | 136 --------- src/testingDatabase.js | 50 +++- src/util/CommunityPostGen.js | 42 +++ src/util/authentication.js | 15 +- 30 files changed, 839 insertions(+), 910 deletions(-) create mode 100644 src/html/portal/user.html create mode 100644 src/services/miiverse-api/routes/policyLists.js delete mode 100644 src/services/web-api/index.js delete mode 100644 src/services/web-api/routes/communities.js delete mode 100644 src/services/web-api/routes/ctr.js delete mode 100644 src/services/web-api/routes/index.js delete mode 100644 src/services/web-api/routes/newPost.js delete mode 100644 src/services/web-api/routes/portal.js delete mode 100644 src/services/web-api/routes/post.js delete mode 100644 src/services/web-api/routes/users.js delete mode 100644 src/services/web-api/routes/web.js diff --git a/package-lock.json b/package-lock.json index 01d9334..4a75895 100644 --- a/package-lock.json +++ b/package-lock.json @@ -216,9 +216,9 @@ } }, "bson": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz", - "integrity": "sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz", + "integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q==" }, "buffer-from": { "version": "1.1.1", @@ -849,12 +849,12 @@ } }, "mongodb": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.4.tgz", - "integrity": "sha512-xGH41Ig4dkSH5ROGezkgDbsgt/v5zbNUwE3TcFsSbDc6Qn3Qil17dhLsESSDDPTiyFDCPJRpfd4887dtsPgKtA==", + "version": "3.5.7", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.7.tgz", + "integrity": "sha512-lMtleRT+vIgY/JhhTn1nyGwnSMmJkJELp+4ZbrjctrnBxuLbj6rmLuJFz8W2xUzUqWmqoyVxJLYuC58ZKpcTYQ==", "requires": { "bl": "^2.2.0", - "bson": "^1.1.1", + "bson": "^1.1.4", "denque": "^1.4.1", "require_optional": "^1.0.1", "safe-buffer": "^5.1.2", @@ -862,15 +862,15 @@ } }, "mongoose": { - "version": "5.9.4", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.4.tgz", - "integrity": "sha512-aUw4hzvJX9UJVN79JcElCwu/YsW1Sl/IDjErwiIX89xz77kmMjQjCmMsXGE1okUEcJGzGnXPqYl9BggXw8Nlvg==", + "version": "5.9.16", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.16.tgz", + "integrity": "sha512-b4HNndgh+dacoLE/2SBF3iBBofeaKL+aGVZH7jnPRc2RXRCplX4sfH5sgoz03ryCSXJ+RQNIfqKAADt/ZBzPDA==", "requires": { - "bson": "~1.1.1", + "bson": "^1.1.4", "kareem": "2.3.1", - "mongodb": "3.5.4", + "mongodb": "3.5.7", "mongoose-legacy-pluralize": "1.0.2", - "mpath": "0.6.0", + "mpath": "0.7.0", "mquery": "3.2.2", "ms": "2.1.2", "regexp-clone": "1.0.0", @@ -920,9 +920,9 @@ } }, "mpath": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.6.0.tgz", - "integrity": "sha512-i75qh79MJ5Xo/sbhxrDrPSEG0H/mr1kcZXJ8dH6URU5jD/knFxCVqVC/gVSW7GIXL/9hHWlT9haLbCXWOll3qw==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz", + "integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg==" }, "mquery": { "version": "3.2.2", diff --git a/package.json b/package.json index 19ced8e..88941ed 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "fs-extra": "^9.0.0", "moment": "^2.24.0", "moment-timezone": "^0.5.27", - "mongoose": "^5.8.3", + "mongoose": "^5.9.16", "mongoose-unique-validator": "^2.0.3", "morgan": "^1.10.0", "node-rsa": "^1.0.8", diff --git a/src/config.json b/src/config.json index efa6087..2ee87f4 100644 --- a/src/config.json +++ b/src/config.json @@ -1,8 +1,11 @@ { "http": { - "port": 8080 + "port": 80 }, - "secret": "b213a890ac28739a0fc0e47f034308c1", + "account_server": "account.miiverse.cc:8080", + "secret": "806590af0a2bf0cf9ce54b0b5c1493a1", + "X-Nintendo-Client-ID": "a2efa818a34fa16b8afbc8a74eba3eda", + "X-Nintendo-Client-Secret": "c91cdb5658bd4954ade78533a339cf9a", "mongoose": { "uri": "mongodb://localhost:27017", "database": "Miiverse", @@ -10,5 +13,8 @@ "useNewUrlParser": true, "useUnifiedTopology": true } - } + }, + "authorized_PNIDs" : [ + 1420636409, 1657414049, 1587572630 + ] } \ No newline at end of file diff --git a/src/database.js b/src/database.js index ead78db..f852e4f 100644 --- a/src/database.js +++ b/src/database.js @@ -46,9 +46,9 @@ async function getTopicByCommunityID(communityID) { }); } -async function getCommunities(numberOfPosts) { +async function getCommunities(numberOfCommunities) { verifyConnected(); - return COMMUNITY.find({}).limit(numberOfPosts); + return COMMUNITY.find({}).limit(numberOfCommunities); } async function getCommunityByTitleID(title_id) { @@ -81,6 +81,13 @@ async function getPostsByUserID(userID) { }); } +async function getNumberPostsByUserID(userID) { + verifyConnected(); + return POST.find({ + pid: userID + }).countDocuments(); +} + async function getHotPostsByCommunity(community, numberOfPosts) { verifyConnected(); return POST.find({ @@ -134,6 +141,7 @@ module.exports = { getHotPostsByCommunity, getPostsByCommunityKey, getPostsByUserID, + getNumberPostsByUserID, getPostByID, getUserByPID, }; \ No newline at end of file diff --git a/src/html/portal/communities.html b/src/html/portal/communities.html index df080aa..beabaa2 100644 --- a/src/html/portal/communities.html +++ b/src/html/portal/communities.html @@ -9,9 +9,9 @@ - + - + diff --git a/src/html/portal/communities_body.html b/src/html/portal/communities_body.html index f5607c8..c13e0af 100644 --- a/src/html/portal/communities_body.html +++ b/src/html/portal/communities_body.html @@ -78,7 +78,6 @@ - OLV_WIIU_NEW_COMMUNITIES Show More diff --git a/src/html/portal/settings_body.html b/src/html/portal/settings_body.html index 29f0530..6f50ca1 100644 --- a/src/html/portal/settings_body.html +++ b/src/html/portal/settings_body.html @@ -15,10 +15,8 @@

Profile Comment

+ placeholder="Write about yourself here."> +

Attention

Please refrain from including any of the following information:
- Your address, telephone number, e-mail address, the name of your school, or any other information that could personally identify you.
@@ -36,7 +34,7 @@

Who should be able to see your profile comment?

Everyone + >Wii U Friends Only @@ -390,7 +388,7 @@ data-modal-types="select-settings" data-action="/settings/profile" - data-name="profile.favorite_community_visibility"> + data-name="profile_favorite_community_visibility">

Profile Settings

diff --git a/src/html/portal/user.html b/src/html/portal/user.html new file mode 100644 index 0000000..6975ec7 --- /dev/null +++ b/src/html/portal/user.html @@ -0,0 +1,278 @@ + + + + + + + + New SUPER MARIO BROS. U + + + + + + + + + + + + + + +
+ +
+ User Menu + +
+
+

Remove from Friends

+
+
+ +

+ + +

+
+
+

Remove this user from your friends? You will be removed from this user's list as well.

+
+
+
+ + +
+
+
+
+
+

Unfollow

+
+
+ +

+ + +

+
+
+

Stop following this user?

+
+
+
+ + +
+
+
+
+
+

Check Friend Request

+
+
+ +

+ + +

+
+
+
+

+

+
+

Cancel your friend request to this user?

+
+
+
+ + +
+
+
+ + +
  • PostsOLV_NUMBER_OF_POSTS
  • +
  • Friends0 / 100
  • +
  • Following0 / 1000
  • +
  • Followers0
  • +
    + +
    + + +
    + +

    OLV_PROFILE_COMMENT

    + +
    + + + + + + + + + + + + + + + + + + +
    CountryUnited StatesBirthday + 01/12 +
    Game Experience + OLV_GAME_EXPERIENCE_LABEL
    Systems OwnedSystem in the Nintendo 3DS Family +
    Favorite Game Genres + + + None selected. + + +
    +
    +
    +

    Favorite Communities

    +
      +
    • + + + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    +
    + + + +
    +

    Recent Drawings

    +
    +

    No drawings posted yet.

    +
    +
    + + + +
    +

    Recently Saved Screenshots

    +
    +

    No screenshots saved yet.

    +
    + View Screenshot Album +
    + +
    +
    +
    + + + +
    +
    +

    yeahPupper's Profile

    +
    +

    +
    +
    + OK +
    +
    +
    + +
    +
    +

    yeahPupper's Profile

    +
    +

    +
    +
    + Cancel + OK +
    +
    +
    + +
    +
    +

    yeahPupper's Profile

    +
    +
    +

    + +
    +
    +
    + Back + OK +
    +
    +
    +
    +
    +
    + Back +
    +
    + + + + + + \ No newline at end of file diff --git a/src/html/portal/user_body.html b/src/html/portal/user_body.html index d1b1a4c..d9e5c64 100644 --- a/src/html/portal/user_body.html +++ b/src/html/portal/user_body.html @@ -1,10 +1,7 @@
    -
    User Menu -
  • Posts0
  • -
  • Friends0 / 100
  • -
  • Following0 / 1000
  • -
  • Followers0
  • +
  • PostsOLV_NUMBER_OF_POSTS
  • +
  • Friends0 / 100
  • +
  • Following0 / 1000
  • +
  • Followers0
  • -

    ..like systemd.

    +

    OLV_PROFILE_COMMENT

    @@ -117,7 +114,7 @@ + OLV_GAME_EXPERIENCE_LABEL @@ -168,13 +165,13 @@ -
    +

    Recent Drawings

    @@ -183,19 +180,19 @@
    -
    +

    Recently Saved Screenshots

    No screenshots saved yet.

    - View Screenshot Album + View Screenshot Album
    diff --git a/src/models/communities.js b/src/models/communities.js index 01d8ca5..e648f19 100644 --- a/src/models/communities.js +++ b/src/models/communities.js @@ -1,10 +1,18 @@ const { Schema, model } = require('mongoose'); const CommunitySchema = new Schema({ + created_at: { + type: Date, + default: new Date(), + }, empathy_count: { type: Number, default: 0 }, + followers: { + type: Number, + default: 0 + }, id: { type: Number, default: 0 @@ -33,6 +41,10 @@ const CommunitySchema = new Schema({ CTR_browser_header: String, WiiU_browser_header: String, description: String, + parent: { + type: Number, + default: null + } }); CommunitySchema.methods.upEmpathy = async function() { @@ -49,6 +61,20 @@ CommunitySchema.methods.downEmpathy = async function() { await this.save(); }; +CommunitySchema.methods.upFollower = async function() { + const followers = this.get('followers'); + this.set('followers', followers + 1); + + await this.save(); +}; + +CommunitySchema.methods.downFollower = async function() { + const followers = this.get('followers'); + this.set('followers', followers - 1); + + await this.save(); +}; + const COMMUNITY = model('COMMUNITY', CommunitySchema); module.exports = { diff --git a/src/models/post.js b/src/models/post.js index ce26f9c..f0fad99 100644 --- a/src/models/post.js +++ b/src/models/post.js @@ -1,5 +1,5 @@ const { Schema, model } = require('mongoose'); -//just testing pull requests + const PostSchema = new Schema({ title_id: String, screen_name: String, @@ -19,12 +19,12 @@ const PostSchema = new Schema({ }, community_id: String, country_id: Number, - created_at: String, + created_at: Date, feeling_id: Number, - id: Number, + id: String, is_autopost: { - type: Number, - default: 0 + type: Number, + default: 0 }, is_community_private_autopost: { type: Number, @@ -55,11 +55,19 @@ const PostSchema = new Schema({ pid: Number, platform_id: Number, region_id: Number, - parent_post: Number, + parent_post: String, reply_count: { type: Number, default: 0 }, + verified: { + type: Boolean, + default: false + }, + parent: { + type: String, + default: null + } }); diff --git a/src/models/user.js b/src/models/user.js index f1c69c7..eb9dac2 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -1,9 +1,21 @@ const { Schema, model } = require('mongoose'); +const notification = new Schema({ + content: String, + link: String, + read: Boolean, + created_at: Date, +}); + const UserSchema = new Schema({ pid: Number, created_at: String, user_id: String, + birthday: Date, + country: String, + pfp_uri: String, + mii: String, + mii_face_url: String, /** * Account Status * 0 - Fine @@ -15,13 +27,248 @@ const UserSchema = new Schema({ type: Number, default: 0 }, - mii: String, + ban_lift_date: Date, + ban_reason: String, official: { type: Boolean, default: false + }, + profile_comment: { + type: String, + default: undefined + }, + game_skill: { + type: Number, + default: 0 + }, + game_skill_visibility: { + type: Boolean, + default: true + }, + profile_comment_visibility: { + type: Boolean, + default: true + }, + birthday_visibility: { + type: Boolean, + default: false + }, + relationship_visibility: { + type: Boolean, + default: false + }, + country_visibility: { + type: Boolean, + default: false + }, + profile_favorite_community_visibility: { + type: Boolean, + default: true + }, + notifications: { + type: Boolean, + default: false + }, + likes: { + type: [Number], + default: [0] + }, + followed_communities: { + type: [Number], + default: [0] + }, + followed_users: { + type: [Number], + default: [0] + }, + following_users: { + type: [Number], + default: [0] + }, + followers: { + type: Number, + default: 0 + }, + following: { + type: Number, + default: 0 + }, + notification_list: { + type: [notification], + default: [{ + content: 'This is your notifications! You\'ll see more stuff here soon!', + link: '/users/me', + read: false, + created_at: new Date(), + }] } + }); +UserSchema.methods.getAccountStatus = async function() { + return this.get('account_status'); +}; + +UserSchema.methods.setAccountStatus = async function(accountStatus) { + this.set('account_status', accountStatus); + await this.save(); +}; +UserSchema.methods.getBanDate = async function() { + return this.get('ban_lift_date'); +}; + +UserSchema.methods.setBanData = async function(banDate) { + this.set('ban_lift_date', banDate); + await this.save(); +}; +UserSchema.methods.getProfileComment = async function() { + return this.get('profile_comment'); +}; +UserSchema.methods.setProfileComment = async function(profileComment) { + this.set('profile_comment', profileComment); + await this.save(); +}; + +UserSchema.methods.getGameSkill = async function() { + return this.get('game_skill'); +}; + +UserSchema.methods.setGameSkill = async function(gameSkill) { + this.set('game_skill', gameSkill); + await this.save(); +}; +UserSchema.methods.getGameSkillVisibility = async function() { + return this.get('game_skill_visibility'); +}; + +UserSchema.methods.setGameSkillVisibility = async function(gameSkillVisibility) { + this.set('game_skill_visibility', gameSkillVisibility); + await this.save(); +}; +UserSchema.methods.getProfileCommentVisibility = async function() { + return this.get('profile_comment_visibility'); +}; + +UserSchema.methods.setProfileCommentVisibility = async function(profileCommentVisibility) { + this.set('profile_comment_visibility', profileCommentVisibility); + await this.save(); +}; +UserSchema.methods.getBirthdayVisibility = async function() { + return this.get('birthday_visibility'); +}; + +UserSchema.methods.setBirthdayVisibility = async function(birthdayVisibility) { + this.set('birthday_visibility', birthdayVisibility); + await this.save(); +}; +UserSchema.methods.getRelationshipVisibility = async function() { + return this.get('relationship_visibility'); +}; + +UserSchema.methods.setRelationshipVisibility = async function(accountStatus) { + this.set('relationship_visibility', accountStatus); + await this.save(); +}; +UserSchema.methods.getFavoriteCommunityVisibility = async function() { + return this.get('profile_favorite_community_visibility'); +}; + +UserSchema.methods.setFavoriteCommunityVisibility = async function(favoriteCommunityVisibility) { + this.set('profile_favorite_community_visibility', favoriteCommunityVisibility); + await this.save(); +}; + +UserSchema.methods.getCountryVisibility = async function() { + return this.get('country_visibility'); +}; + +UserSchema.methods.setCountryVisibility = async function(countryVisibility) { + this.set('country_visibility', countryVisibility); + await this.save(); +}; + +UserSchema.methods.addToLikes = async function(postID) { + const likes = this.get('likes'); + likes.addToSet(postID); + await this.save(); +} + +UserSchema.methods.removeFromLike = async function(postID) { + const likes = this.get('likes'); + likes.pull(postID); + await this.save(); +} + +UserSchema.methods.addToCommunities = async function(postID) { + const communities = this.get('followed_communities'); + communities.addToSet(postID); + await this.upFollowing(); + await this.save(); +} + +UserSchema.methods.removeFromCommunities = async function(postID) { + const communities = this.get('followed_communities'); + communities.pull(postID); + await this.downFollowing(); + await this.save(); +} + +UserSchema.methods.addToUsers = async function(postID) { + const users = this.get('followed_users'); + users.addToSet(postID); + await this.upFollowing(); + await this.save(); +} + +UserSchema.methods.removeFromUsers = async function(postID) { + const users = this.get('followed_users'); + users.pull(postID); + await this.downFollowing(); + await this.save(); +} + +UserSchema.methods.addToFollowers = async function(postID) { + const users = this.get('following_users'); + users.addToSet(postID); + await this.upFollower(); + await this.save(); +} + +UserSchema.methods.removeFromFollowers = async function(postID) { + const users = this.get('following_users'); + users.pull(postID); + await this.downFollower(); + await this.save(); +} + +UserSchema.methods.upFollower = async function() { + const followers = this.get('followers'); + this.set('followers', followers + 1); + + await this.save(); +}; + +UserSchema.methods.downFollower = async function() { + const followers = this.get('followers'); + this.set('followers', followers - 1); + + await this.save(); +}; + +UserSchema.methods.upFollowing = async function() { + const following = this.get('following'); + this.set('following', following + 1); + + await this.save(); +}; + +UserSchema.methods.downFollowing = async function() { + const following = this.get('following'); + this.set('following', following - 1); + + await this.save(); +}; + const USER = model('USER', UserSchema); module.exports = { diff --git a/src/server.js b/src/server.js index 27bb6ff..625d3a4 100644 --- a/src/server.js +++ b/src/server.js @@ -10,7 +10,6 @@ const { http: { port } } = config; const app = express(); const miiverse = require('./services/miiverse-api'); -const webApi = require('./services/web-api'); app.set('etag', false); app.disable('x-powered-by'); @@ -29,7 +28,6 @@ app.use(xmlparser); // import the servers into one app.use(miiverse); -app.use(webApi); // 404 handler logger.info('Creating 404 status handler'); diff --git a/src/services/miiverse-api/index.js b/src/services/miiverse-api/index.js index 1a3158e..a1b343f 100644 --- a/src/services/miiverse-api/index.js +++ b/src/services/miiverse-api/index.js @@ -29,5 +29,6 @@ discovery.use('/v1/endpoint', routes.DISCOVERY); api.use('/v1/posts', routes.POST); api.use('/v1/communities/', routes.COMMUNITY); api.use('/v1/people/', routes.PEOPLE); +discovery.use('/p01/', routes.POLICY); module.exports = router; \ No newline at end of file diff --git a/src/services/miiverse-api/routes/communities.js b/src/services/miiverse-api/routes/communities.js index d9794f5..d61ac08 100644 --- a/src/services/miiverse-api/routes/communities.js +++ b/src/services/miiverse-api/routes/communities.js @@ -5,6 +5,22 @@ const comPostGen = require('../../../util/CommunityPostGen'); const processHeaders = require('../../../util/authentication'); /* GET post titles. */ +router.get('/', function (req, res) { + database.connect().then(async e => { + const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]); + let community = await database.getCommunityByTitleID(paramPack.title_id); + if (community != null) { + let response = await comPostGen.Communities(community); + res.contentType("application/xml"); + res.send(response); + } else { + res.status(404); + res.send(); + } + + }); +}); + router.get('/0/posts', function (req, res) { database.connect().then(async e => { /* Parse out parameters from URL and headers */ diff --git a/src/services/miiverse-api/routes/index.js b/src/services/miiverse-api/routes/index.js index 2e145e3..63bb8c5 100644 --- a/src/services/miiverse-api/routes/index.js +++ b/src/services/miiverse-api/routes/index.js @@ -3,4 +3,5 @@ module.exports = { POST: require('./post'), COMMUNITY: require('./communities'), PEOPLE: require('./people'), + POLICY: require('./policyLists'), }; \ No newline at end of file diff --git a/src/services/miiverse-api/routes/policyLists.js b/src/services/miiverse-api/routes/policyLists.js new file mode 100644 index 0000000..916c4b3 --- /dev/null +++ b/src/services/miiverse-api/routes/policyLists.js @@ -0,0 +1,92 @@ +var express = require('express'); +var router = express.Router(); +const xmlbuilder = require("xmlbuilder"); +var multer = require('multer'); +var upload = multer(); + +router.get('/policylist/1/1/US', upload.none(), async function (req, res, next) { + let xml = xmlbuilder.create("result") + .e("has_error", "0").up() + .e("version", "1").up() + .e("request_name", "posts").up() + .e("topic") + .e("community_id", community.community_id).up() + .up() + .e("posts"); + let response = { + MajorVersion: 1, + MinorVersion: 0, + ListId: 1924, + DefaultStop: false, + ForceVersionUp: true, + UpdateTime: '2020-03-03T02:51:02+0000', + Priority: { + TitleId: '0005003010016000', + TaskId: 'olvinfo', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '0005003010016100', + TaskId: 'olvinfo', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '0005003010016200', + TaskId: 'olvinfo', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500301001600a', + TaskId: 'olv1', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500301001610a', + TaskId: 'olv1', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500301001620a', + TaskId: 'olv1', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '0005001010040000', + TaskId: 'oltopic', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '0005001010040100', + TaskId: 'oltopic', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '0005001010040200', + TaskId: 'oltopic', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500101005a000', + TaskId: 'Chat', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500101005a100', + TaskId: 'Chat', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500101005a200', + TaskId: 'Chat', + Level: 'EXPEDITE', + }, + Priority: { + TitleId: '000500101004c100', + TaskId: 'plog', + Level: 'EXPEDITE', + }, + }; + res.send("\n" + xml(response)); +}); + +module.exports = router; \ No newline at end of file diff --git a/src/services/miiverse-api/routes/post.js b/src/services/miiverse-api/routes/post.js index f195bb5..214dc54 100644 --- a/src/services/miiverse-api/routes/post.js +++ b/src/services/miiverse-api/routes/post.js @@ -15,7 +15,8 @@ router.post('/', upload.none(), async function (req, res, next) { { let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]); - if(pid == null) + console.log(pid); + if(pid === null) { throw new Error('The User token was not valid'); } @@ -23,7 +24,6 @@ router.post('/', upload.none(), async function (req, res, next) { { let usrObj; usrObj = await util.data.processUser(pid); - const creationDate = moment().format('YYYY-MM-DD HH:MM:SS'); let appData = ""; if (req.body.app_data) { appData = req.body.app_data.replace(/\0/g, "").trim(); @@ -53,7 +53,7 @@ router.post('/', upload.none(), async function (req, res, next) { topic_tag: req.body.topic_tag, community_id: req.body.community_id, country_id: paramPackData.country_id, - created_at: creationDate, + created_at: new Date(), feeling_id: req.body.feeling_id, id: snowflake.nextId(), is_autopost: req.body.is_autopost, @@ -61,10 +61,11 @@ router.post('/', upload.none(), async function (req, res, next) { is_app_jumpable: req.body.is_app_jumpable, language_id: req.body.language_id, mii: usrObj.mii, - mii_face_url: "http://mii-images.account.pretendo.cc/", + mii_face_url: "https://mii-images.account.pretendo.cc/", pid: pid, platform_id: paramPackData.platform_id, region_id: paramPackData.region_id, + parent: null, }; const newPost = new POST(document); newPost.save(); diff --git a/src/services/web-api/index.js b/src/services/web-api/index.js deleted file mode 100644 index e8df2c6..0000000 --- a/src/services/web-api/index.js +++ /dev/null @@ -1,35 +0,0 @@ -const express = require('express'); -const subdomain = require('express-subdomain'); -const logger = require('../../logger'); -const routes = require('./routes'); - -// Main router for endpointsindex.js -const router = express.Router(); - -// Router to handle the subdomain restriction -const api = express.Router(); -const web = express.Router(); -const ctr = express.Router(); -const portal = express.Router(); - -// Create subdomains -logger.info('[MIIVERSE] Creating \'web api\' subdomain'); -router.use(subdomain('web.olv', web)); -router.use(subdomain('ctr.olv', ctr)); -router.use(subdomain('portal.olv', portal)); - -// Setup routes -web.use('/', routes.WEB); -ctr.use('/titles/show', routes.CTR); -portal.use('/', routes.PORTAL); -portal.use('/v1/communities/', routes.COMMUNITY); -portal.use('/v1/posts/', routes.POST); -portal.use('/post', routes.NEWPOST); -web.use('/v1/communities/', routes.COMMUNITY); -api.use('/v1/communities/', routes.COMMUNITY); -api.use('/v1/posts/', routes.POST); -api.use('/post', routes.NEWPOST); -api.use('/users/', routes.USERS); -portal.use('/users/', routes.USERS); - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/communities.js b/src/services/web-api/routes/communities.js deleted file mode 100644 index a9011fd..0000000 --- a/src/services/web-api/routes/communities.js +++ /dev/null @@ -1,91 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -var multer = require('multer'); -const snowflake = require('node-snowflake').Snowflake; -const consts = require('../../../consts.json'); -const { COMMUNITY } = require('../../../models/communities'); -let PNG = require('pngjs').PNG; -// configure multer -var storage = multer.memoryStorage(); -var upload = multer({ storage: storage }); - -/* GET post titles. */ -router.get('/list', function (req, res) { - database.connect().then(async e => { - /* Parse out parameters from URL and headers */ - //const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - //"[0:1]=1407375153523200" - let community = await database.getCommunities(5); - let formatType = parseInt(req.query.format); - switch(formatType) - { - case 0: - let body = '\n' + - ' '; - body += ''; - res.send('' - + '' + '' + body + ''); - break; - case 1: - let response = []; - for(let i = 0; i < community.length; i++) - { - response.push(community[i]); - } - res.send(JSON.stringify(response)); - break; - } - }); -}); -router.get('/images', function (req, res) { - database.connect().then(async e => { - let community = await database.getCommunityByID(req.query.community_id); - let response = { - name: community.name, - description: community.description, - platform_id: community.platform_id, - title_id: community.title_id[0], - CTR_browser_header: community.CTR_browser_header, - WiiU_browser_header: community.WiiU_browser_header, - browser_icon: community.browser_icon - }; - res.send(response); - - }); -}); -router.get('/uploads/*', function (req, res) { - let fileName = req.originalUrl.replace('/v1/communities/uploads/', '').trim(); - res.sendFile(fileName, { root: './uploads/' }); -}); -router.post('/new', upload.fields([{name: 'browserIcon', maxCount: 1}, { name: 'CTRbrowserHeader', maxCount: 1}, { name: 'WiiUbrowserHeader', maxCount: 1}]), async function (req, res, next) { - const files = JSON.parse(JSON.stringify(req.files)); - const document = { - empathy_count: 0, - id: snowflake.nextId(), - has_shop_page: req.body.has_shop_page, - platform_id: req.body.platform_ID, - icon: req.body.icon, - title_ids: req.body.title_ids, - title_id: req.body.title_ids, - community_id: snowflake.nextId(), - is_recommended: req.body.is_recommended, - name: req.body.name, - browser_icon: `data:image/png;base64,${req.files.browserIcon[0].buffer.toString('base64')}`, - CTR_browser_header: `data:image/png;base64,${req.files.CTRbrowserHeader[0].buffer.toString('base64')}`, - WiiU_browser_header: `data:image/png;base64,${req.files.WiiUbrowserHeader[0].buffer.toString('base64')}`, - description: req.body.description, - }; - const newCommunity = new COMMUNITY(document); - newCommunity.save(); - res.sendStatus(200) - -}); - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/ctr.js b/src/services/web-api/routes/ctr.js deleted file mode 100644 index 16afa2b..0000000 --- a/src/services/web-api/routes/ctr.js +++ /dev/null @@ -1,12 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -const comPostGen = require('../../../util/CommunityPostGen'); -const processHeaders = require('../../../util/authentication'); - -/* GET post titles. */ -router.get('/', function (req, res) { - res.sendFile("ctr.html", { root: 'html' }); -}); - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/index.js b/src/services/web-api/routes/index.js deleted file mode 100644 index 20d4037..0000000 --- a/src/services/web-api/routes/index.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - USERS: require('./users'), - POST: require('./post'), - NEWPOST: require('./newPost'), - COMMUNITY: require('./communities'), - WEB: require('./web'), - CTR: require('./ctr'), - PORTAL: require('./portal') -}; \ No newline at end of file diff --git a/src/services/web-api/routes/newPost.js b/src/services/web-api/routes/newPost.js deleted file mode 100644 index 8b76b79..0000000 --- a/src/services/web-api/routes/newPost.js +++ /dev/null @@ -1,104 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const moment = require('moment'); -var xml = require('object-to-xml'); -const { POST } = require('../../../models/post'); -const util = require('../../../util/authentication'); -const database = require('../../../database'); -const snowflake = require('node-snowflake').Snowflake; -var maxSize = 1 * 1000 * 1000; -var multer = require('multer'); -var upload = multer({ - limits: { fileSize: maxSize } -}); -router.post('/', upload.none(), async function (req, res, next) { - try - { - let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]); - if(pid == null) - { - throw new Error('The User token was not valid'); - } - else - { - let usrObj; - usrObj = await util.data.processUser(pid); - const creationDate = moment().format('YYYY-MM-DD HH:MM:SS'); - let appData = ""; - if (req.body.app_data) { - appData = req.body.app_data.replace(/\0/g, "").trim(); - } - let painting = ""; - if (req.body.painting) { - painting = req.body.painting.replace(/\0/g, "").trim(); - } - let paintingURI = ""; - if (req.body.painting) { - paintingURI = await util.data.processPainting(painting); - } - let screenshot = ""; - if (req.body.screenshot) { - screenshot = req.body.screenshot.replace(/\0/g, "").trim(); - } - const document = { - title_id: req.body.olive_title_id, - screen_name: usrObj.user_id, - body: req.body.body, - app_data: appData, - painting: painting, - painting_uri: paintingURI, - screenshot: screenshot, - url: req.body.url, - search_key: req.body.search_key, - topic_tag: req.body.topic_tag, - community_id: req.body.community_id, - country_id: paramPackData.country_id, - created_at: creationDate, - feeling_id: req.body.feeling_id, - id: snowflake.nextId(), - is_autopost: req.body.is_autopost, - is_spoiler: req.body.is_spoiler, - is_app_jumpable: req.body.is_app_jumpable, - language_id: req.body.language_id, - mii: usrObj.mii, - mii_face_url: "http://mii-images.account.pretendo.cc/", - pid: pid, - platform_id: paramPackData.platform_id, - region_id: paramPackData.region_id, - }; - const newPost = new POST(document); - newPost.save(); - res.sendStatus(200); - } - } - catch (e) - { - res.set("Content-Type", "application/xml"); - res.statusCode = 400; - response = { - result: { - has_error: 1, - version: 1, - code: 400, - error_code: 7, - message: "POSTING_FROM_NNID" - } - }; - res.send("\n" + xml(response)); - } - -}); - -router.post('/*/empathies', upload.none(), function (req, res, next) { - let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - let pid = req.originalUrl.replace('/v1/posts/', '').replace('/empathies','').trim(); - database.connect().then(async emp => { - const post = await database.getPostByID(pid); - await post.upEmpathy(); - }); - res.status(200); - res.send(); -}); - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/portal.js b/src/services/web-api/routes/portal.js deleted file mode 100644 index 8ee59f7..0000000 --- a/src/services/web-api/routes/portal.js +++ /dev/null @@ -1,248 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -const fs = require('fs-extra'); -const util = require('../../../util/authentication'); -const comPostGen = require('../../../util/CommunityPostGen'); -const processHeaders = require('../../../util/authentication'); - -/* GET post titles. */ -router.get('/titles/show', function (req, res) { - res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2') - res.redirect('/communities'); -}); -router.get('/settings/profile', function (req, res) { - res.sendFile("settings_body.html", { root: 'src/html/portal' }); -}); -router.get('/friend_messages', function (req, res) { - res.sendFile("messages_body.html", { root: 'src/html/portal' }); -}); -router.get('/news/my_news', function (req, res) { - res.sendFile("notifications_body.html", { root: 'src/html/portal' }); -}); -router.get('/identified_user_posts', function (req, res) { - res.sendFile("verified_post_body.html", { root: 'src/html/portal' }); -}); -router.get('/', function (req, res) { - res.sendFile("feed_body.html", { root: 'src/html/portal' }); -}); -router.get('/users/*', function (req, res) { - res.sendFile("user_body.html", { root: 'src/html/portal' }); -}); -router.get('/wiiu-emulation.js', function (req, res) { - res.sendFile("wiiu-emulation.js", { root: 'src/html/portal' }); -}); -router.get('/portal.js', function (req, res) { - res.sendFile("portal.js", { root: 'src/html/portal' }); -}); -router.get('/portal.css', function (req, res) { - res.sendFile("portal.css", { root: 'src/html/portal' }); -}); -router.get('/*/wiiu-emulation.js', function (req, res) { - res.sendFile("wiiu-emulation.js", { root: 'src/html/portal' }); -}); -router.get('/*/portal.js', function (req, res) { - res.sendFile("portal.js", { root: 'src/html/portal' }); -}); -router.get('/*/portal.css', function (req, res) { - res.sendFile("portal.css", { root: 'src/html/portal' }); -}); -router.post('/posts/*/empathies', function (req, res, next) { - let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - let pid = req.originalUrl.replace('/posts/', '').replace('/empathies','').trim(); - console.log(pid); - database.connect().then(async emp => { - let post = await database.getPostByID(parseInt(pid)); - await post.upEmpathy(); - }); - res.status(200); - res.send(); -}); -router.post('/posts/*/empathies.delete', function (req, res, next) { - let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - let pid = req.originalUrl.replace('/posts/', '').replace('/empathies.delete','').trim(); - console.log(pid); - database.connect().then(async emp => { - let post = await database.getPostByID(parseInt(pid)); - await post.downEmpathy(); - }); - res.status(200); - res.send(); -}); -router.post('/posts/*/replies', async function (req, res, next) { - try - { - let postID = req.originalUrl.replace('/posts', '').split('/').pop().split('?')[0]; - let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]); - if(pid == null) - { - throw new Error('The User token was not valid'); - } - else - { - let usrObj; - usrObj = await util.data.processUser(pid); - const creationDate = moment().format('YYYY-MM-DD HH:MM:SS'); - let appData = ""; - if (req.body.app_data) { - appData = req.body.app_data.replace(/\0/g, "").trim(); - } - let painting = ""; - if (req.body.painting) { - painting = req.body.painting.replace(/\0/g, "").trim(); - } - let paintingURI = ""; - if (req.body.painting) { - paintingURI = await util.data.processPainting(painting); - } - let screenshot = ""; - if (req.body.screenshot) { - screenshot = req.body.screenshot.replace(/\0/g, "").trim(); - } - const document = { - title_id: req.body.olive_title_id, - screen_name: usrObj.user_id, - body: req.body.body, - app_data: appData, - painting: painting, - painting_uri: paintingURI, - screenshot: screenshot, - url: req.body.url, - created_at: creationDate, - feeling_id: req.body.feeling_id, - id: snowflake.nextId(), - is_autopost: req.body.is_autopost, - is_spoiler: req.body.is_spoiler, - mii: usrObj.mii, - mii_face_url: "http://mii-images.account.pretendo.cc/", - }; - const newPost = new POST(document); - newPost.save(); - res.sendStatus(200); - } - } - catch (e) - { - res.set("Content-Type", "application/xml"); - res.statusCode = 400; - response = { - result: { - has_error: 1, - version: 1, - code: 400, - error_code: 7, - message: "POSTING_FROM_NNID" - } - }; - res.send("\n" + xml(response)); - } - -}); -router.get('/posts/*', function (req, res) { - database.connect().then(async e => { - try - { - let postID = req.originalUrl.replace('/posts', '').split('/').pop().split('?')[0]; - console.log(postID); - let post = await database.getPostByID(parseInt(postID)); - let community = await database.getCommunityByTitleID(post.title_id); - if(post === null) - res.sendStatus(404); - else - { - let file = ''; - if (req.query._pjax === "#body") - file = await fs.readFile(`src/html/portal/post_body.html`, 'utf-8'); - else - file = await fs.readFile(`src/html/portal/post.html`, 'utf-8'); - let newFile = file.replace(/OLV_DISPLAY_NAME/g, post.screen_name) - .replace(/OLV_TOPIC_TAG/g, post.topic_tag) - .replace(/OLV_ICON_STANDIN/g, community.browser_icon) - .replace(/OLV_COMMUNITY_ID/g, community.community_id) - .replace(/OLV_POST_TIMESTAMP/g, post.created_at) - .replace(/OLV_PAGE_TITLE_STANDIN/g, community.name) - .replace(/OLV_POST_ID/g, post.id); - let postContent = ''; - if(post.painting_uri !== undefined && post.painting_uri !== '') - postContent += '

    '; - else - postContent += '

    ' + post.body + '

    '; - if(post.screenshot !== undefined && post.screenshot !== '') - postContent += '

    ' + post.body + '

    '+ - '

    '; - else if(post.url !== undefined && post.url !== '') - postContent += ''; - - res.send(newFile.replace('OLV_POST_CONTENT', postContent)); - } - } - catch (e) { - res.sendStatus(404); - } - - }); -}); -router.get('/titles/*', function (req, res) { - database.connect().then(async e => { - let communityID = req.originalUrl.replace('/titles/', '').replace('?_pjax=%23body', ''); - let community = await database.getCommunityByID(communityID); - if(community === null) - res.sendStatus(404); - else - { - let file = ''; - if (req.query._pjax === "#body") - file = await fs.readFile(`src/html/portal/community_body.html`, 'utf-8'); - else - file = await fs.readFile(`src/html/portal/community.html`, 'utf-8'); - let newFile = file.replace(/COMMUNITY_TITLE_ID_STANDIN/g, communityID) - .replace(/OLV_TITLEID_STANDIN/g, community.title_id[0]) - .replace(/OLV_ICON_STANDIN/g, community.browser_icon) - .replace(/OLV_HEADER_STANDIN/g, community.WiiU_browser_header) - .replace(/OLV_PAGE_TITLE_STANDIN/g, community.name) - res.send(newFile); - } - - }); -}); - -router.get('/communities', function (req, res) { - database.connect().then(async e => { - let communities = await database.getCommunities(6); - if(communities === null) - res.sendStatus(404); - else - { - let file = ''; - if (req.query._pjax === "#body") - file = await fs.readFile(`src/html/portal/communities_body.html`, 'utf-8'); - else - file = await fs.readFile(`src/html/portal/communities.html`, 'utf-8'); - let communityBody = '
      '; - for(let i = 0; i < communities.length; i++) - { - communityBody += '
    • ' + - '' + - '' + - '
      ' + - '
      ' + - '' + communities[i].name + ''; - switch(parseInt(communities[i].platform_id)) - { - case 0: - communityBody += 'Wii U Games'; - break; - case 1: - communityBody += '3DS Games'; - break; - case 2: - communityBody += 'Both Platform Games'; - break; - } - } - res.send(file.replace('OLV_WIIU_NEW_COMMUNITIES', communityBody + '
    • ')); - } - - }); -}); -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/post.js b/src/services/web-api/routes/post.js deleted file mode 100644 index e4127b1..0000000 --- a/src/services/web-api/routes/post.js +++ /dev/null @@ -1,148 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -const consts = require('../../../consts.json'); - -router.get('/', function (req, res) { - database.connect().then(async e => { - /* Parse out parameters from URL and headers */ - //const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]); - //"[0:1]=1407375153523200" - let community = await database.getCommunityByID(req.query.community_id); - let posts; - console.log(parseFloat(req.query.community_id)); - switch(parseFloat(req.query.type)) - { - case 0: - posts = await database.getPostsByCommunity(community, parseInt(req.query.limit)); - break; - case 1: - posts = await database.getHotPostsByCommunity(community, parseInt(req.query.limit)); - break; - } - let formatType = parseInt(req.query.format); - let body = ''; - let platformIDTag = ''; - switch(parseInt(community.platform_id)) - { - case 0: - platformIDTag = consts.Wii_U_Platform_Tag; - break; - case 1: - platformIDTag = consts.CTR_Platform_Tag; - break; - case 2: - platformIDTag = consts.Both_Platform_Tag; - break; - } - switch(formatType) - { - case 0: - body = '
    Game Experience - Expert
    Systems Owned
    ' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - ''; - for(let i = 0; i < posts.length; i++) - { - let paintingURI; - if(posts[i].painting_uri === undefined) - paintingURI = consts.No_Painting; - else - paintingURI = posts[i].painting_uri; - let postBody; - if(posts[i].body === undefined) - postBody = 'No text'; - else - postBody = posts[i].body; - body += '' + '' + - '' + - '' + - ''; - } - body += '' + '
    IconDescription
    ' + community.description +'
    Screen NameBody TextYeah CountPainting
    ' + posts[i].screen_name + '' + '' + postBody + '' + posts[i].empathy_count + '
    '; - res.send('' - + '' + '' + body + ''); - break; - case 1: - body = - '' + - '' + - '' + - ''; - for(let i = 0; i < posts.length; i++) - { - let postBody = ''; - if(posts[i].painting_uri === undefined && posts[i].body !== undefined) - postBody = ''; - else if(posts[i].painting_uri !== undefined && posts[i].body === undefined) - postBody = ''; - else - postBody = ''; - - body += '' + '' + - '' + - '' + postBody + ''; - } - body += '' + '
    ' + '' + posts[i].body + '' + 'No Data
    ' + posts[i].screen_name + 'Yeah: ' + posts[i].empathy_count + '
    '; - res.send('' - + '' + '' + body + ''); - break; - case 2: - let response = []; - for(let i = 0; i < posts.length; i++) - { - response.push(posts[i]); - } - res.send(JSON.stringify(response)); - break; - } - }); -}); - -router.get('/*', function (req, res) { - let post_id = req.originalUrl.replace('/posts/', '').trim(); - database.connect().then(async emp => { - const post = await database.getPostByID(post_id); - let post_body; - if(post.body === undefined) - post_body = 'No Text'; - else - post_body = post.body; - let post_painting_uri; - if(post.painting_uri === undefined) - post_painting_uri = consts.No_Painting; - else - post_painting_uri = post.painting_uri; - let body = - '\n' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + '' + - '' + - '' + - '' + - '' + '
    Screen NameBody TextYeah CountPainting
    ' + post.screen_name + '' + post_body + '' + post.empathy_count + '
    '; - res.send('' - + '' + '' + body + ''); - }); -}); - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/users.js b/src/services/web-api/routes/users.js deleted file mode 100644 index 82f4a8a..0000000 --- a/src/services/web-api/routes/users.js +++ /dev/null @@ -1,61 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -const consts = require('../../../consts.json'); - -router.get('/*/check_can_post.json', function (req, res) { - res.send({"success":1,"remaining_today_posts":30}); -}); -router.get('/*', function (req, res) { - database.connect().then(async e => { - let PID = req.originalUrl.replace('/users/', '').trim(); - let posts = await database.getPostsByUserID(PID); - let userPosts = ''; - let totalEmpathy = 0; - for(let i = 0; i < posts.length; i++) - { - totalEmpathy += posts[i].empathy_count; - let paintingURI; - if(posts[i].painting_uri === undefined) - paintingURI = consts.No_Painting; - else - paintingURI = posts[i].painting_uri; - let postBody; - if(posts[i].body === undefined) - postBody = 'No text'; - else - postBody = posts[i].body; - userPosts += '' + '' + postBody + '' + - '' + posts[i].empathy_count + '' + - ''; - } - let body = - '\n' + - '' + - '' + - '' + - '' + - '\n' + - '' + - '' + - '' + - '' + - '' + - ''; - body += userPosts + '
    User NameTotal Yeah!
    ' + posts[0].screen_name + '' + totalEmpathy + '
    Body TextYeah CountPainting
    '; - res.send('' - + '' + '' + body + ''); - - }); -}); - - -module.exports = router; \ No newline at end of file diff --git a/src/services/web-api/routes/web.js b/src/services/web-api/routes/web.js deleted file mode 100644 index 48cb3a2..0000000 --- a/src/services/web-api/routes/web.js +++ /dev/null @@ -1,136 +0,0 @@ -var express = require('express'); -var router = express.Router(); -const database = require('../../../database'); -const comPostGen = require('../../../util/CommunityPostGen'); -const processHeaders = require('../../../util/authentication'); - -/* GET post titles. */ -router.get('/', function (req, res) { - res.send( - '\n' + - '\n' + - '\n' + - '\n' + - '

    Pretendo Miiverse Demo

    \n' + - '\n' + - '
    \n' + - '
    \n' + - '
    \n' + - '
    \n' + - '\n' + - '\n' + - '\n' + - '\n' + - '\n' - ) -}); - -router.get('/admin/communities/new', function (req, res) { - res.send( - '\n' + - '\n' + - '\n' + - '\n' + - '

    New Community Form

    \n' + - '\n' + - '

    Fill out all the information below. Title ID\'s must be in the decimal value form, not the hex form

    \n' + - '\n' + - '
    \n' + - '
    \n' + - '
    \n' + - ' \n' + - '
    \n' + - '
    \n' + - ' \n' + - '
    \n' + - '
    \n' + - ' \n' + - '
    \n' + - '
    \n' + - ' \n' + - '
    \n' + - '
    \n' + - ' \n' + - '
    \n' + - '
    \n' + - ' \n' + - 'Browser Icon
    \n' + - '
    \n' + - ' \n' + - '3DS Browser Banner
    \n' + - '
    \n' + - 'Wii U Browser Banner
    \n' + - '
    \n' + - ' Is Recommended?\n' + - ' \n' + - ' \n' + - ' \n' + - '
    \n' + - ' \n' + - ' Has Shop Page? \n' + - ' \n' + - ' \n' + - ' \n' + - '
    \n' + - ' \n' + - ' Platform \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' + - '
    \n' + - ' \n' + - ' \n' + - '
    \n' + - '\n' + - '\n' + - '\n' - ) -}); - -module.exports = router; \ No newline at end of file diff --git a/src/testingDatabase.js b/src/testingDatabase.js index 0454337..4f772fa 100644 --- a/src/testingDatabase.js +++ b/src/testingDatabase.js @@ -2,7 +2,50 @@ const crypto = require('crypto'); const NodeRSA = require('node-rsa'); const fs = require('fs-extra'); const config = require('./config.json'); -let B64token = 'C9EFfkLjs6/81whPNBXOEqDPGQiDykCDwS/B4KcQDcAJxyvnXEure4xfwS/GPQKbRqLoE/QCTPEHh2q9B6TgdWJYNvnNb3wpvwhHy5CJ0hqwYxVaKE0iZcxQVK7QyJlhya3sE3K0HTmP1DqVISxYkEyCF7ofSZMoRcbKUvxfYHbALnh+Hbdl5F3nEUIcmBPijsVzi8kJSe2aQYR8n1X3b0J0HFO5QzHAwMiwiZBOyHnIdHtpsoWalDDkjoQfufSP8LcNFA=='; +const util = require('./util/authentication'); +const database = require('./database'); + +let b = "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" + + "AAAA5vgbwDsbNA=="; + +console.log(util.data.processServiceToken('Lg8Ix5uzYLZ01ip/P3UMt4iEPVjJYjh41L5r+hndp30gzEGxgvx830MWvH7jhiNBIvJbCAwHSEKJF2RvHYL+xq3oCVON8e1yy/eZlWKKW3SOvVMRiXlEr66zPMqZSIIxtYLvn1+7MM3qJPIuTIzR/4/JGeAE6KxPJuFK7zkROEYu9LSfPKGY0O2Sv6rnrZze3NHwHtT70uI7FXbP0P3t8yVQLgtAbxktcS5+NeGSwpVwpnO54rMMZjgJ7l42VKPGhEzHBw==')); +/*let B64token = 'C9EFfkLjs6/81whPNBXOEqDPGQiDykCDwS/B4KcQDcAJxyvnXEure4xfwS/GPQKbRqLoE/QCTPEHh2q9B6TgdWJYNvnNb3wpvwhHy5CJ0hqwYxVaKE0iZcxQVK7QyJlhya3sE3K0HTmP1DqVISxYkEyCF7ofSZMoRcbKUvxfYHbALnh+Hbdl5F3nEUIcmBPijsVzi8kJSe2aQYR8n1X3b0J0HFO5QzHAwMiwiZBOyHnIdHtpsoWalDDkjoQfufSP8LcNFA=='; let token = Buffer.from(B64token, 'base64'); console.log(B64token); console.log(config.secret); @@ -45,3 +88,8 @@ if (!calculatedSignature.equals(signature)) { console.log('Token signature did not match'); console.log("fuck"); } +*/ +database.connect().then(async e => { + console.log('running'); + console.log(await util.data.processUser(1566682802)); +}); diff --git a/src/util/CommunityPostGen.js b/src/util/CommunityPostGen.js index 66e6e87..542d568 100644 --- a/src/util/CommunityPostGen.js +++ b/src/util/CommunityPostGen.js @@ -107,6 +107,48 @@ class CommunityPostGen { return xml.end({ pretty: true, allowEmpty: true }); } + static async Communities(community) { + const xml = xmlbuilder.create("result") + .e("has_error", "0").up() + .e("version", "1").up() + .e("request_name", "communities").up() + .e("communities") + .e("community") + .e('olive_community_id', community.community_id).up() + .e('community_id', community.community_id).up() + .e("name", community.name).up() + .e("description", community.description).up() + .e("icon").up() + .e("icon_3ds").up() + .e("pid").up() + .e("app_data").up() + .e("is_user_community", 0).up() + .up() + .e("community") + .e('olive_community_id', community.community_id + 100).up() + .e('community_id', community.community_id + 100).up() + .e("name", community.name + '- Nintendo Levels').up() + .e("description", community.description).up() + .e("icon").up() + .e("icon_3ds").up() + .e("pid").up() + .e("app_data", 'TVZNSQI').up() + .e("is_user_community", 0).up() + .up() + .e("community") + .e('olive_community_id', community.community_id + 200).up() + .e('community_id', community.community_id + 200).up() + .e("name", community.name + '- User Levels').up() + .e("description", community.description).up() + .e("icon").up() + .e("icon_3ds").up() + .e("pid").up() + .e("app_data", 'TVZNSQE').up() + .e("is_user_community", 0).up() + .up() + .up(); + return xml.end({ pretty: true, allowEmpty: true }); + } /* TODO Again, some constants */ static async SinglePostResponse(post) { let xml = xmlbuilder.create("result") diff --git a/src/util/authentication.js b/src/util/authentication.js index 00d69c7..6efa7c9 100644 --- a/src/util/authentication.js +++ b/src/util/authentication.js @@ -14,14 +14,17 @@ let PNG = require('pngjs').PNG; let methods = { processUser: function(pid) { return new Promise(function(resolve, reject) { + console.log('running me'); database.connect().then(async yeet => { let userObject = await database.getUserByPID(pid); + console.log(userObject); if(userObject != null) resolve(userObject); else { + console.log('else'); await request({ - url: "http://account.jemverse.xyz/v1/api/miis?pids=" + pid, + url: "http://" + config.account_server + "/v1/api/miis?pids=" + pid, headers: { 'X-Nintendo-Client-ID': 'a2efa818a34fa16b8afbc8a74eba3eda', 'X-Nintendo-Client-Secret': 'c91cdb5658bd4954ade78533a339cf9a' @@ -38,12 +41,17 @@ let methods = { official: false }; const newUsrObj = new USER(newUsr); + console.log(newUsrObj); newUsrObj.save(); resolve(newUsr); } else + { + console.log('fail'); reject(); - }) + } + + }); } @@ -67,8 +75,7 @@ let methods = { { let B64token = Buffer.from(token, 'base64'); let decryptedToken = this.decryptToken(B64token); - let pid = decryptedToken.readUInt32LE(0x2); - return pid; + return decryptedToken.readUInt32LE(0x2); } catch(e) {