File tree Expand file tree Collapse file tree 13 files changed +353
-284
lines changed
Expand file tree Collapse file tree 13 files changed +353
-284
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const filePath = process.argv[2]
1717
1818; ( async ( ) => {
1919 try {
20- const opts = {
20+ const status = await transloadit . createAssembly ( {
2121 files : {
2222 file1 : filePath ,
2323 } ,
@@ -33,9 +33,7 @@ const filePath = process.argv[2]
3333 } ,
3434 } ,
3535 waitForCompletion : true ,
36- }
37-
38- const status = await transloadit . createAssembly ( opts )
36+ } )
3937 console . log ( 'Your WebP file:' , status . results . webp [ 0 ] . url )
4038 } catch ( err ) {
4139 console . error ( 'createAssembly failed' , err )
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ const transloadit = new Transloadit({
1717const firstName = 'myProductionS3'
1818const secondName = 'myStagingS3'
1919
20+ /**
21+ * @type {import('transloadit').CreateTemplateCredentialParams }
22+ */
2023const credentialParams = {
2124 name : firstName ,
2225 type : 's3' ,
Original file line number Diff line number Diff line change 1313const got = require ( 'got' )
1414const { createWriteStream } = require ( 'fs' )
1515const { Transloadit } = require ( 'transloadit' )
16+ const assert = require ( 'assert' )
1617
1718const transloadit = new Transloadit ( {
1819 authKey : /** @type {string } */ ( process . env . TRANSLOADIT_KEY ) ,
@@ -23,7 +24,7 @@ const filePath = process.argv[2]
2324
2425; ( async ( ) => {
2526 try {
26- const opts = {
27+ const status = await transloadit . createAssembly ( {
2728 files : {
2829 file1 : filePath ,
2930 } ,
@@ -40,14 +41,14 @@ const filePath = process.argv[2]
4041 } ,
4142 } ,
4243 waitForCompletion : true ,
43- }
44-
45- const status = await transloadit . createAssembly ( opts )
44+ } )
4645
4746 // Now save the file
4847 const outPath = './output-face.jpg'
4948 const stream = createWriteStream ( outPath )
50- await got . default . stream ( status . results . facesDetected [ 0 ] . url ) . pipe ( stream )
49+ const { url } = status . results . facesDetected [ 0 ]
50+ assert ( url != null )
51+ await got . default . stream ( url ) . pipe ( stream )
5152 console . log ( 'Your cropped face has been saved to' , outPath )
5253 } catch ( err ) {
5354 console . error ( 'createAssembly failed' , err )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const filePath = process.argv[2]
1717
1818; ( async ( ) => {
1919 try {
20- const opts = {
20+ const status = await transloadit . createAssembly ( {
2121 files : {
2222 file1 : filePath ,
2323 } ,
@@ -31,9 +31,7 @@ const filePath = process.argv[2]
3131 } ,
3232 } ,
3333 waitForCompletion : true ,
34- }
35-
36- const status = await transloadit . createAssembly ( opts )
34+ } )
3735 console . log ( 'Your PNG file:' , status . results . png [ 0 ] . url )
3836 } catch ( err ) {
3937 console . error ( 'createAssembly failed' , err )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const filePath = process.argv[2]
1717
1818; ( async ( ) => {
1919 try {
20- const opts = {
20+ const status = await transloadit . createAssembly ( {
2121 files : {
2222 file1 : filePath ,
2323 } ,
@@ -34,9 +34,7 @@ const filePath = process.argv[2]
3434 } ,
3535 } ,
3636 waitForCompletion : true ,
37- }
38-
39- const status = await transloadit . createAssembly ( opts )
37+ } )
4038 console . log ( 'Your resized image:' , status . results . resize [ 0 ] . url )
4139 } catch ( err ) {
4240 console . error ( 'createAssembly failed' , err )
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const transloadit = new Transloadit({
1313 authSecret : /** @type {string } */ ( process . env . TRANSLOADIT_SECRET ) ,
1414} )
1515
16+ /** @type {import('transloadit').TemplateContent } */
1617const template = {
1718 steps : {
1819 encode : {
@@ -22,7 +23,7 @@ const template = {
2223 } ,
2324 thumbnail : {
2425 use : 'encode' ,
25- robot : '/video/thumbnails ' ,
26+ robot : '/video/thumbs ' ,
2627 } ,
2728 } ,
2829}
Original file line number Diff line number Diff line change 11import { Readable } from 'stream'
2- import { PaginationList } from './Transloadit '
2+ import { PaginationList , PaginationListWithCount } from './apiTypes '
33
44// eslint-disable-next-line no-unused-vars
5- type FetchPage < T > = ( pageno : number ) => PaginationList < T > | PromiseLike < PaginationList < T > >
5+ type FetchPage < T > = (
6+ pageno : number
7+ ) =>
8+ | PaginationList < T >
9+ | PromiseLike < PaginationList < T > >
10+ | PaginationListWithCount < T >
11+ | PromiseLike < PaginationListWithCount < T > >
612
713export default class PaginationStream < T > extends Readable {
814 private _fetchPage : FetchPage < T >
@@ -33,8 +39,10 @@ export default class PaginationStream<T> extends Readable {
3339 }
3440
3541 try {
36- const { count, items } = await this . _fetchPage ( ++ this . _pageno )
37- this . _nitems = count
42+ const { items, ...rest } = await this . _fetchPage ( ++ this . _pageno )
43+ if ( 'count' in rest ) {
44+ this . _nitems = rest . count
45+ }
3846
3947 this . _items = Array . from ( items )
4048 this . _items . reverse ( )
You can’t perform that action at this time.
0 commit comments