@@ -3,7 +3,8 @@ import fetch from "node-fetch";
33const { version } = require ( "../package.json" ) ;
44const linguist = require ( "@sourcebin/linguist/dist/linguist.json" ) ;
55
6- const url = "https://sourceb.in" ;
6+ const url_long = "https://sourceb.in" ;
7+ const url_short = "sourceb.in" ;
78
89export class Bin {
910 public key : string ;
@@ -13,7 +14,7 @@ export class Bin {
1314
1415 constructor ( options : BinOptions ) {
1516 this . key = options . key ;
16- this . url = `${ url } /${ this . key } ` ;
17+ this . url = `${ url_long } /${ this . key } ` ;
1718 this . created = options . created ;
1819 this . files = options . files ;
1920 }
@@ -54,7 +55,22 @@ interface Language {
5455}
5556
5657export async function get ( k : string ) : Promise < Bin > {
57- const { files, key, created } = await fetch ( `${ url } /api/bins/${ k } ` , {
58+
59+ if ( / ( h t t p s ? ) ( : \/ \/ ) ? ( .+ ) \. ( .* ) \/ ? / . test ( k ) ) {
60+ if ( k . includes ( url_short ) ) {
61+ const match = k . match ( / s o u r c e b .i n \/ ( .+ ) / ) ;
62+
63+ if ( ! match ) {
64+ return Promise . reject ( "Url must have a valid path!" ) ;
65+ }
66+
67+ k = match [ 1 ] . replace ( / \/ / g, "" ) ;
68+ } else {
69+ return Promise . reject ( `Url must be a valid '${ url_short } ' url!` ) ;
70+ }
71+ }
72+
73+ const { files, key, created } = await fetch ( `${ url_long } /api/bins/${ k } ` , {
5874 headers : {
5975 "Content-Type" : "application/json" ,
6076 "User-Agent" : "SourceBin Wrapper/" + version
@@ -89,7 +105,7 @@ export async function create(binFiles: Array<BinFile>): Promise<Bin | string> {
89105 } )
90106 } ;
91107
92- const { key, message } = await fetch ( `${ url } /api/bins` , {
108+ const { key, message } = await fetch ( `${ url_long } /api/bins` , {
93109 method : "post" ,
94110 headers : {
95111 "Content-Type" : "application/json" ,
0 commit comments