| … | |
… | |
| 13 | use WeBWorK::PG::Translator; |
13 | use WeBWorK::PG::Translator; |
| 14 | use WeBWorK::PG::IO; |
14 | use WeBWorK::PG::IO; |
| 15 | use Benchmark; |
15 | use Benchmark; |
| 16 | use MIME::Base64 qw( encode_base64 decode_base64); |
16 | use MIME::Base64 qw( encode_base64 decode_base64); |
| 17 | |
17 | |
| 18 | my $debugOn =0; |
18 | my $debugOn = 1; |
| 19 | my $PASSWORD = $Global::PASSWORD; |
19 | my $PASSWORD = $Global::PASSWORD; |
| 20 | |
20 | |
| 21 | |
21 | |
| 22 | my $TEMPDIRECTORY = $Global::TEMPDIRECTORY; |
22 | my $TEMPDIRECTORY = $Global::TEMPDIRECTORY; |
| 23 | my $TEMP_BASE_URL = $Global::TEMP_BASE_URL; |
23 | my $TEMP_BASE_URL = $Global::TEMP_BASE_URL; |
| 24 | my $externalLatexPath = $Global::externalLatexPath; |
24 | my $externalLatexPath = $Global::externalLatexPath; |
| … | |
… | |
| 31 | my $tmp_directory_permission = $Global::tmp_directory_permission; |
31 | my $tmp_directory_permission = $Global::tmp_directory_permission; |
| 32 | my $numericalGroupID = $Global::numericalGroupID; # group ID for webadmin |
32 | my $numericalGroupID = $Global::numericalGroupID; # group ID for webadmin |
| 33 | |
33 | |
| 34 | sub tex2pdf { |
34 | sub tex2pdf { |
| 35 | |
35 | |
| 36 | my $rh = shift; |
36 | my $rh = shift; |
| 37 | local($|)=1; |
37 | local($|) = 1; |
| 38 | my $out = {}; |
38 | my $out = {}; |
| 39 | unless ($rh->{pw} eq $PASSWORD ) { |
39 | unless ($rh->{pw} eq $PASSWORD ) { |
| 40 | $out->{error}=404; |
40 | $out->{error} = 404; |
| 41 | return($out); |
41 | return($out); |
| 42 | } |
42 | } |
| 43 | #obtain the path to the file |
43 | #obtain the path to the file |
| 44 | my $filePath = $rh->{fileName}; |
44 | my $filePath = $rh->{fileName}; |
| 45 | my @pathElements = split("/", $filePath); |
45 | my @pathElements = split("/", $filePath); |
| 46 | |
46 | |
| 47 | # grab the last element as the fileName |
47 | # grab the last element as the fileName |
| 48 | #remove the extension from the file name |
48 | #remove the extension from the file name |
| 49 | my $fileName = pop @pathElements; |
49 | my $fileName = pop @pathElements; |
| 50 | $fileName =~ s/\.pg$//; |
50 | $fileName =~ s/\.pg$//; |
| 51 | |
51 | |
| 52 | #Create the full url and the full directory path -- If pathElements is empty this can give an extra //? Should I worry? |
52 | #Create the full url and the full directory path -- If pathElements is empty this can give an extra //? Should I worry? maybe |
| 53 | my $url = $TEMP_BASE_URL. join("/",@pathElements). "/$fileName.pdf"; |
53 | my $url = $TEMP_BASE_URL. join("/",@pathElements); |
|
|
54 | $url .= '/' unless $url =~ m|/$|; # only add / if it is needed. |
|
|
55 | $url .= "$fileName.pdf"; |
| 54 | my $texFileBasePath = $TEMPDIRECTORY.join("/",@pathElements) . "/$fileName"; |
56 | my $texFileBasePath = $TEMPDIRECTORY.join("/",@pathElements); |
|
|
57 | $texFileBasePath .= '/' unless $texFileBasePath =~ m|/$|; |
|
|
58 | $texFileBasePath .= "$fileName"; |
| 55 | |
59 | |
| 56 | # create the intermediate directories if they don't exists |
60 | # create the intermediate directories if they don't exists |
| 57 | # create a dummy .pdf file |
61 | # create a dummy .pdf file |
| 58 | surePathToTmpFile2($texFileBasePath.'.pdf'); |
62 | surePathToTmpFile2($texFileBasePath.'.pdf'); |
| 59 | # my $filePermission = '0775'; |
63 | # my $filePermission = '0775'; |