@@ -2,8 +2,8 @@ let headers = require('../utils/headers.js');
22let constants = require ( '../utils/constants.js' ) ;
33
44async function _getReplId ( username , slug ) {
5- let info = await variables
6- . fetch ( `https://staging.replit.com /data/repls/@${ username } /${ slug } ` , {
5+ let info = await constants
6+ . fetch ( `${ constants . restful } /data/repls/@${ username } /${ slug } ` , {
77 method : 'GET' ,
88 headers
99 } )
@@ -23,25 +23,26 @@ class Repl {
2323 let slug = this . slug ;
2424
2525 let id = await _getReplId ( username , slug ) ;
26- let info = await variables
27- . fetch ( variables . graphql , {
26+ let info = await constants
27+ . fetch ( constants . graphql , {
2828 method : 'POST' ,
2929 headers,
3030 body : JSON . stringify ( {
3131 query : `
3232 query Repl($id: String!) {
3333 repl(id: $id) {
3434 ... on Repl {
35- ${ variables . replAttributes }
35+ ${ constants . replAttributes }
3636 }
3737 }
3838 }` ,
3939 variables : JSON . stringify ( {
4040 id : id
4141 } )
4242 } )
43- } )
44- . then ( res => res . json ( ) ) ;
43+ } ) . then ( res => res . json ( ) ) ;
44+
45+ if ( info . errors ) throw new Error ( `Replit GraphQL Error(s): ${ JSON . stringify ( info . errors ) } ` ) ;
4546
4647 if ( ! info . data . repl ) {
4748 throw new Error ( `${ slug } is not a repl. Please query repls on Repl.it.` ) ;
@@ -54,8 +55,8 @@ class Repl {
5455 let username = this . username ;
5556 let slug = this . slug ;
5657
57- let info = await variables
58- . fetch ( `https://staging.replit.com /data/repls/@${ username } /${ slug } ` , {
58+ let info = await constants
59+ . fetch ( `${ constants . restful } /data/repls/@${ username } /${ slug } ` , {
5960 method : 'GET' ,
6061 headers
6162 } )
@@ -72,19 +73,32 @@ class Repl {
7273 let username = this . username ;
7374 let slug = this . slug ;
7475
75- let info = await variables
76+ let info = await constants
7677 . fetch ( `https://replangs.rayhanadev.repl.co/${ username } /${ slug } ` , {
7778 method : 'GET' ,
7879 headers
79- } )
80- . then ( res => res . json ( ) ) ;
80+ } ) . then ( res => res . json ( ) ) ;
8181
8282 if ( info . error ) {
8383 throw new Error ( `REPLangs Error: ${ info . error } .` ) ;
8484 } else {
8585 return info ;
8686 }
8787 }
88+
89+ async replTitleGen ( ) {
90+ let info = await constants
91+ . fetch ( constants . graphql , {
92+ method : 'POST' ,
93+ headers,
94+ body : JSON . stringify ( {
95+ query : `query ReplTitle() { replTitle }`
96+ } )
97+ } ) . then ( res => res . json ( ) ) ;
98+
99+ if ( info . errors ) throw new Error ( `Replit GraphQL Error(s): ${ JSON . stringify ( info . errors ) } ` ) ;
100+ else return info . data . replTitle ;
101+ }
88102}
89103
90104module . exports = {
0 commit comments