@@ -31,14 +31,16 @@ export class Bin {
3131}
3232
3333export class BinFile {
34- public languageId : number ;
35- public language : Language ;
34+ public raw : string ;
3635 public content : string ;
36+ public language : Language ;
37+ public languageId : number ;
3738
3839 constructor ( options : BinFileOptions ) {
40+ this . raw = `${ url_long } /${ options . raw } ` ;
41+ this . content = options . content ;
3942 this . languageId = getLanguageId ( options . languageId ) || 372 ;
4043 this . language = linguist [ this . languageId ] ;
41- this . content = options . content ;
4244 }
4345
4446 public object ( ) : any {
@@ -53,23 +55,24 @@ interface BinOptions {
5355}
5456
5557interface BinFileOptions {
58+ raw ?: string ;
5659 content : string ;
5760 languageId ?: number | string ;
5861}
5962
6063interface Language {
6164 name : string ;
62- extension : string ;
63- aliases ?: Array < string > ;
6465 aceMode : string ;
66+ aliases ?: Array < string > ;
67+ extension : string ;
6568}
6669
6770export async function get ( k : string ) : Promise < Bin > {
6871 if ( / ( ( h t t p s ? ) ( : \/ \/ ) ) ? ( .+ ) \. ( .* ) \/ ? / . test ( k ) ) {
6972 if ( urls . filter ( url => k . includes ( url ) ) ) {
7073
7174 const [
72- match , , , , key
75+ match , , , , key
7376 ] = k . match ( / s ( ( o u r c e ) | ( r c ) ) b \. i n \/ ( \S + ) / ) || [ ] ;
7477
7578 if ( ! match ) {
@@ -82,7 +85,7 @@ export async function get(k: string): Promise<Bin> {
8285 }
8386 }
8487
85- const { files, key, created } = await fetch ( `${ url_long } /api/bins/${ k } ` , {
88+ const { files, key, created } : Bin = await fetch ( `${ url_long } /api/bins/${ k } ` , {
8689 headers : {
8790 'Content-Type' : 'application/json' ,
8891 'User-Agent' : 'SourceBin Wrapper/' + version
@@ -94,10 +97,11 @@ export async function get(k: string): Promise<Bin> {
9497
9598 const binFiles : Array < BinFile > = [ ] ;
9699
97- files . forEach ( file => {
100+ files . forEach ( ( file , index ) => {
98101 binFiles . push ( new BinFile ( {
99102 content : file . content ,
100- languageId : file . languageId
103+ languageId : file . languageId ,
104+ raw : `${ key } /${ index } `
101105 } ) ) ;
102106 } ) ;
103107
@@ -117,7 +121,10 @@ export async function create(binFiles: Array<BinFile>): Promise<Bin | string> {
117121 files : binFiles
118122 . map ( file => file . object ( ) )
119123 . map ( file => {
120- return { content : file . content , languageId : file . languageId } ;
124+ return {
125+ content : file . content ,
126+ languageId : file . languageId
127+ } ;
121128 } )
122129 } ;
123130
@@ -128,7 +135,8 @@ export async function create(binFiles: Array<BinFile>): Promise<Bin | string> {
128135 'User-Agent' : 'SourceBin Wrapper/' + version
129136 } ,
130137 body : JSON . stringify ( body )
131- } ) . then ( checkStatus )
138+ } )
139+ . then ( checkStatus )
132140 . then ( res => res . json ( ) ) ;
133141
134142 if ( message ) {
@@ -138,7 +146,12 @@ export async function create(binFiles: Array<BinFile>): Promise<Bin | string> {
138146 return new Bin ( {
139147 key : key ,
140148 created : new Date ( ) ,
141- files : binFiles
149+ files : binFiles . map ( ( file , i ) => {
150+ return {
151+ ...file . object ( ) ,
152+ raw : `${ url_long } /${ key } /${ i } `
153+ } ;
154+ } )
142155 } ) ;
143156}
144157
0 commit comments