-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for standard video formats * fix content type in video response * restore content length header for Safari support * remove standard .ts video format support * adding audio resource support and adding test cases * misc refactor * refactor audio and video files according to better understanding of container formats * clean up TODO comment
- Loading branch information
1 parent
bcd2524
commit 0f3e230
Showing
11 changed files
with
369 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.DS_Store | ||
*.log | ||
.greenwood/ | ||
.nyc_output/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/cli/src/plugins/resource/plugin-standard-audio.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* | ||
* Manages web standard resource related operations for audio formats. | ||
* This is a Greenwood default plugin. | ||
* | ||
*/ | ||
import fs from 'fs/promises'; | ||
import { ResourceInterface } from '../../lib/resource-interface.js'; | ||
|
||
class StandardAudioResource extends ResourceInterface { | ||
constructor(compilation, options) { | ||
super(compilation, options); | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Audio_codecs | ||
// https://www.thoughtco.com/audio-file-mime-types-3469485 | ||
this.extensions = ['mid', 'mp3', 'm3u', 'oga', 'ra', 'wav']; | ||
} | ||
|
||
async shouldServe(url) { | ||
const extension = url.pathname.split('.').pop(); | ||
|
||
return url.protocol === 'file:' && this.extensions.includes(extension); | ||
} | ||
|
||
async serve(url) { | ||
const extension = url.pathname.split('.').pop(); | ||
const body = await fs.readFile(url); | ||
let contentType = ''; | ||
|
||
switch (extension) { | ||
|
||
case '3gp': | ||
contentType = 'audio/3gp'; | ||
break; | ||
case 'mid': | ||
contentType = 'audio/mid'; | ||
break; | ||
case 'mp3': | ||
contentType = 'audio/mpeg'; | ||
break; | ||
case 'mp4': | ||
contentType = 'audio/mp4'; | ||
break; | ||
case 'm3u': | ||
contentType = 'audio/x-mpegurl'; | ||
break; | ||
case 'oga': | ||
case 'ogg': | ||
contentType = `audio/${extension}`; | ||
break; | ||
case 'ra': | ||
contentType = 'audio/vnd.rn-realaudio'; | ||
break; | ||
case 'wav': | ||
contentType = 'audio/vnd.wav'; | ||
break; | ||
default: | ||
|
||
} | ||
|
||
return new Response(body, { | ||
headers: new Headers({ | ||
'Content-Type': contentType, | ||
'Content-Length': String(body.toString().length) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
const greenwoodPluginStandardAudio = { | ||
type: 'resource', | ||
name: 'plugin-standard-audio', | ||
provider: (compilation, options) => new StandardAudioResource(compilation, options) | ||
}; | ||
|
||
export { greenwoodPluginStandardAudio }; |
78 changes: 78 additions & 0 deletions
78
packages/cli/src/plugins/resource/plugin-standard-video.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
* Manages web standard resource related operations for video formats. | ||
* This is a Greenwood default plugin. | ||
* | ||
*/ | ||
import fs from 'fs/promises'; | ||
import { ResourceInterface } from '../../lib/resource-interface.js'; | ||
|
||
class StandardVideoResource extends ResourceInterface { | ||
constructor(compilation, options) { | ||
super(compilation, options); | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_codecs | ||
// https://help.encoding.com/knowledge-base/article/correct-mime-types-for-serving-video-files/ | ||
this.extensions = ['3gp', 'avi', 'flv', 'm3u8', 'mp4', 'mov', 'ogg', 'ogv', 'wmv']; | ||
} | ||
|
||
async shouldServe(url) { | ||
const extension = url.pathname.split('.').pop(); | ||
|
||
return url.protocol === 'file:' && this.extensions.includes(extension); | ||
} | ||
|
||
async serve(url) { | ||
const extension = url.pathname.split('.').pop(); | ||
const body = await fs.readFile(url); | ||
let contentType = ''; | ||
|
||
switch (extension) { | ||
|
||
case '3gp': | ||
contentType = 'video/3gpp'; | ||
break; | ||
case 'avi': | ||
contentType = 'video/x-msvideo'; | ||
break; | ||
case 'flv': | ||
contentType = 'video/x-flv'; | ||
break; | ||
case 'm3u8': | ||
contentType = 'application/x-mpegURL'; | ||
break; | ||
case 'mp4': | ||
contentType = 'video/mp4'; | ||
break; | ||
case 'mov': | ||
contentType = 'video/quicktime'; | ||
break; | ||
case 'ogg': | ||
contentType = `application/${extension}`; | ||
break; | ||
case 'ogv': | ||
contentType = `video/${extension}`; | ||
break; | ||
case 'wmv': | ||
contentType = 'video/x-ms-wmv'; | ||
break; | ||
default: | ||
|
||
} | ||
|
||
return new Response(body, { | ||
headers: new Headers({ | ||
'Content-Type': contentType, | ||
'Content-Length': String(body.toString().length) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
const greenwoodPluginStandardVideo = { | ||
type: 'resource', | ||
name: 'plugin-standard-video', | ||
provider: (compilation, options) => new StandardVideoResource(compilation, options) | ||
}; | ||
|
||
export { greenwoodPluginStandardVideo }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.