1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- import * as openpgp from 'openpgp' ;
18- import { createReadStream , createWriteStream , readFileSync } from 'fs' ;
19- import { pipeline } from 'stream/promises' ;
20- import { Readable } from 'stream' ;
21-
2217import type { Config } from '../config/Config' ;
2318
2419import Debug from 'debug' ;
2520const log = Debug ( 'CID:postprocessFile' ) ;
2621
2722
28- export interface PostprocessFileResult {
29- encryptedFilePath ?: string
30- }
23+ export interface PostprocessFileResult { }
3124
3225interface PostprocessFileInput {
3326 config : Config . FileConfiguration ,
@@ -36,45 +29,8 @@ interface PostprocessFileInput {
3629
3730export async function postprocessFile ( { config, filePath } : PostprocessFileInput ) : Promise < PostprocessFileResult > {
3831 log ( '------------ postprocessFile -----------------' ) ;
39- let encryptedFilePath : string | undefined ;
4032
4133 if ( ! config . post_processing ) return { }
4234
43- if ( config . post_processing . encryption ) {
44- encryptedFilePath = await encryptFile ( {
45- filePath : filePath ,
46- keyPath : config . post_processing . encryption . key_path
47- } ) ;
48- }
49-
50- return {
51- encryptedFilePath
52- }
53- }
54-
55-
56- type EncryptFileInput = {
57- filePath : string ;
58- keyPath : string ;
59- }
60- export async function encryptFile ( { filePath, keyPath } : EncryptFileInput ) {
61- const publicKeyArmoured = readFileSync ( keyPath , "utf-8" ) ;
62- const publicKey = await openpgp . readKey ( { armoredKey : publicKeyArmoured } ) ;
63-
64- const webStream = Readable . toWeb ( createReadStream ( filePath ) ) ;
65-
66- const encryptionStream = await openpgp . encrypt ( {
67- message : await openpgp . createMessage ( { binary : webStream } ) ,
68- encryptionKeys : publicKey ,
69- format : "binary"
70- } ) ;
71-
72- const outputPath = `${ filePath } .gpg` ;
73-
74- const nodeWritable = createWriteStream ( outputPath ) ;
75- const nodeReadable = Readable . fromWeb ( encryptionStream ) ;
76-
77- await pipeline ( nodeReadable , nodeWritable ) ;
78-
79- return outputPath ;
35+ return { }
8036}
0 commit comments