Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 99b64b6

Browse files
author
Ray Arayilakath
committed
New Configuration Setup, Meta Changes, and Lint
1 parent 1148c04 commit 99b64b6

File tree

9 files changed

+37
-22
lines changed

9 files changed

+37
-22
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ node_modules
55
test
66

77
# replit
8-
.replit
8+
.replit
9+
10+
# replapi
11+
.replapirc.json

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from 'fs';
2+
import path from 'path';
13
import replapi from './src/source.js';
24

35
const defaultInitVariables = {
@@ -37,13 +39,13 @@ export default function ReplAPI(initVariables) {
3739
defaultInitVariables[key] = value;
3840
}
3941
}
40-
global.initVariables = defaultInitVariables;
42+
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), JSON.stringify(defaultInitVariables), { encoding: 'utf8' });
4143
} else {
42-
global.initVariables = defaultInitVariables;
44+
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), JSON.stringify(defaultInitVariables), { encoding: 'utf8' });
4345
}
4446

4547
return {
46-
defaults: global.initVariables,
48+
defaults: defaultInitVariables,
4749
Board: replapi.Board,
4850
Comment: replapi.Comment,
4951
CustomDataQuery: replapi.CustomDataQuery,

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"main": "index.js",
77
"scripts": {
88
"start": "node index.js",
9-
"test": "echo \"No Tests Specified\""
9+
"test": "echo \"No Tests Specified\"",
10+
"lint": "eslint . --ext .js",
11+
"lint:fix": "eslint . --ext .js --fix"
1012
},
1113
"repository": {
1214
"type": "git",

src/classes/Database.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
import fetch from 'node-fetch';
2+
import fs from 'fs';
3+
import path from 'path';
24

35
import headers from '../utils/headers.js';
46
import constants from '../utils/constants.js';
57

68
function hash(value, salt) {
7-
const hash = crypto.createHmac('sha512', salt);
8-
hash.update(value);
9-
const result = hash.digest('hex');
9+
const hashItem = crypto.createHmac('sha512', salt);
10+
hashItem.update(value);
11+
const result = hashItem.digest('hex');
1012
return {
1113
salt,
1214
hashedpassword: result,
1315
};
1416
}
1517

1618
function compare(value, hashData) {
17-
const resultData = _hash(value, hashData.salt);
19+
const resultData = hash(value, hashData.salt);
1820
if (resultData.hashedpassword === hashData.hashedpassword) {
1921
return true;
2022
}
2123
return false;
2224
}
2325

2426
let exportable;
27+
const isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
2528

26-
if (false) {
27-
let exportable = class Database {
29+
if (isExperimentalFeaturesEnabled) {
30+
exportable = class Database {
2831
constructor(replitdbtoken, salt, options) {
2932
this.replitdbtoken = replitdbtoken || process.env.REPLIT_DB_URL.split('/')[4];
3033
this.salt = salt;
3134
this.options = options;
3235
}
33-
36+
3437
async set(key, value) {
3538
const info = await fetch(`https://kv.replit.com/v0/${this.replitdbtoken}`, {
3639
method: 'POST',
3740
headers,
3841
body: `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`,
3942
}).then((res) => res.json());
4043
}
41-
44+
4245
async get(key) {
4346
const info = await fetch(`https://kv.replit.com/v0/${this.replitdbtoken}/${key}`, {
4447
method: 'GET',
@@ -47,7 +50,7 @@ if (false) {
4750
res.json();
4851
});
4952
}
50-
53+
5154
async delete(key) {
5255
const info = await fetch(`https://kv.replit.com/v0/${this.replitdbtoken}/${key}`, {
5356
method: 'GET',
@@ -56,7 +59,7 @@ if (false) {
5659
res.json();
5760
});
5861
}
59-
}
62+
};
6063
} else {
6164
exportable = function noExperimentalFeatures() {
6265
console.log('Experimental Features are not enabled. To learn more about experimental features please visit the documentation.');

src/classes/Login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fetch from 'node-fetch';
33
import headers from '../utils/headers.js';
44
import constants from '../utils/constants.js';
55

6-
async function _getCookies(username, password) {
6+
async function getCookies(username, password) {
77
if (['RayhanADev'].includes(global.initVariables.username)) {
88
const info = await fetch(constants.login, {
99
method: 'POST',
@@ -31,7 +31,7 @@ async function _getCookies(username, password) {
3131
export default class Login {
3232
async withCredentials(password) {
3333
if (['RayhanADev'].includes(global.initVariables.username)) {
34-
global.cookies = await _getCookies(global.initVariables.username, password);
34+
global.cookies = await getCookies(global.initVariables.username, password);
3535
} else {
3636
throw new Error(
3737
`${global.initVariables.username} is not whitelisted. Please contact @RayhanADev in ReplTalk to talk about getting added to the whitelist.`,

src/classes/Notifications.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import fetch from 'node-fetch';
2+
import fs from 'fs';
3+
import path from 'path';
24

35
import headers from '../utils/headers.js';
46
import constants from '../utils/constants.js';
57

68
let exportable;
9+
const isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
710

8-
if (false) {
11+
if (isExperimentalFeaturesEnabled) {
912
exportable = class Notifications {
1013
async postReplyNotification(after, count) {
1114
if (!global.cookies) {

src/classes/User.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default class User {
8686

8787
async function recurse(recurseAfter) {
8888
if (recurseAfter === null) return;
89-
console.log(recurseAfter)
9089
const info = await fetch(constants.graphql, {
9190
method: 'POST',
9291
headers,

src/utils/constants.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const initVariables = global.initVariables || {
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
const initVariables = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))) || {
25
username: undefined,
36
captcha: {
47
token: undefined,
@@ -24,7 +27,7 @@ export default {
2427
subscriptionAttributes: 'id, userId, customerId, planId, timeUpdated, timeCreated, timeDeleted',
2528
userAttributes: 'id, username, firstName, lastName, bio, isVerified, displayName, fullName, url, isLoggedIn, isSubscribed, timeCreated, isBannedFromBoards, karma, isHacker, image',
2629
boardAttributes: 'id, name, description, slug, cta, titleCta, bodyCta, template, buttonCta, color, replRequired, isLocked, isAnswerable, isPrivate, timeCreated, timeUpdated, url, canPost',
27-
replAttributes: 'id, language, isProject, isPrivate, isStarred, title, slug, description, folderId, isRenamed, url, timeCreated, timeUpdated, isOwner, tags { id }, pinnedToProfile, files, hostedUrl, terminalUrl',
30+
replAttributes: 'id, language, isProject, isPrivate, isStarred, title, slug, description, folderId, isRenamed, url, timeCreated, timeUpdated, isOwner, tags { id }, pinnedToProfile, files, hostedUrl, terminalUrl, reactions { id, count }',
2831
commentAttributes: `id, body, voteCount, timeCreated, timeUpdated, url, isAuthor, canEdit, canVote, canComment, hasVoted, canReport, hasReported, isAnswer, canSelectAsAnswer, canUnselectAsAnswer, preview(length: ${initVariables.markdown.length || 150}, removeMarkdown: ${initVariables.markdown.removeMarkdown || true})`,
2932
postAttributes: `id, title, body, showHosted, voteCount, commentCount, isPinned, isLocked, timeCreated, timeUpdated, url, isAnnouncement, isAuthor, canEdit, canComment, canVote, canPin, canSetType, canChangeBoard, canLock, hasVoted, canReport, hasReported, isAnswerable, tutorialPages, preview(length: ${initVariables.markdown.length || 150}, removeMarkdown: ${initVariables.markdown.removeMarkdown || true})`,
3033
graphql: `${initVariables.endpoints.gql || 'https://staging.replit.com/graphql'}`,

src/utils/headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default {
33
Accept: 'application/json',
44
'Accept-Encoding': 'gzip, deflate, br',
55
Connection: 'keep-alive',
6-
'X-Requested-With': 'REPLAPIit',
6+
'X-Requested-With': 'ReplAPI.it',
77
Referrer: 'https://replit.com/',
88
Origin: 'https://replit.com/',
99
};

0 commit comments

Comments
 (0)