-
Notifications
You must be signed in to change notification settings - Fork 279
add Paste code to submit feature #2720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
62985ba
56f076e
aa8ed35
3893628
3376c11
bf9d7bc
add44de
74e36d9
dbe2363
723f8d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,21 +97,20 @@ | |
| $problem = $formPaste->get('problem')->getData(); | ||
| $language = $formPaste->get('language')->getData(); | ||
| $codeContent = $formPaste->get('code_content')->getData(); | ||
|
|
||
| $problemShortName = $problem->getContestProblems()->first()->getShortName(); | ||
|
|
||
| if ($codeContent == null || empty(trim($codeContent))) { | ||
| $this->addFlash('danger', 'No code content provided.'); | ||
| return $this->redirectToRoute('team_index'); | ||
| } | ||
|
|
||
| $tempDir = sys_get_temp_dir(); | ||
| $tempFileName = sprintf( | ||
| 'submission_%s_%s_%s.%s', | ||
| $user->getUsername(), | ||
| $problem->getName(), | ||
| date('Y-m-d_H-i-s'), | ||
| $saveFileDir = sys_get_temp_dir(); | ||
| $saveFileName = sprintf( | ||
| '%s.%s', | ||
| $problemShortName, | ||
| $language->getExtensions()[0] | ||
| ); | ||
| $tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName); | ||
| $saveFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $saveFileName); | ||
|
|
||
| if ($language->getExtensions()[0] == 'java' || $language->getExtensions()[0] == 'kt') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hardcoding Java and Kotlin here, use the Similarly, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to use what we built here so that the entry point works the same regardless of the upload method: https://github.com/DOMjudge/domjudge/blob/main/webapp/src/Form/Type/SubmitProblemType.php#L66 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand how to use $language->getRequireEntryPoint(). For example, in the case of Java, when using paste_code, the entry_point might still be no. In this case, how can I use this to determine the file name standard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the remark here is that instead of listing the current languages which need an entrypoint, use that function @meisterT linked and use it from there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The function should be checking whether the language in the form requires an entrypoint, which seems to be different from my current situation, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would it be different? You check for 2 languages here and determine the entrypoint for those. If there are other languages like this we would also want to pick them up. People can add more languages besides those 2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vmcj If so, there might be an issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, in the case of Java, it can be configured to not require an entry point. In this scenario, under the original upload mode, the uploaded file itself becomes the entry point. However, due to the characteristics of the Java language, the file name must match the main class name. In the case of the paste code mode, regardless of whether an entry point is required or not, the user must be allowed to specify the main class name. Otherwise, I won’t be able to save the file correctly, which will result in a compile error. |
||
| $entryPoint = $formPaste->get('entry_point')->getData() ?: null; | ||
|
|
@@ -121,17 +120,17 @@ | |
| $this->addFlash('danger', 'Invalid entry point name.'); | ||
| return $this->redirectToRoute('team_index'); | ||
| } | ||
| $tempFileName = $entryPoint . '.' . $language->getExtensions()[0]; | ||
| $saveFileName = $entryPoint . '.' . $language->getExtensions()[0]; | ||
| } else { | ||
| $entryPoint = $tempFileName; | ||
| $entryPoint = $saveFileName; | ||
| } | ||
|
|
||
| $tempFilePath = $tempDir . DIRECTORY_SEPARATOR . $tempFileName; | ||
| file_put_contents($tempFilePath, $codeContent); | ||
| $saveFilePath = $saveFileDir . DIRECTORY_SEPARATOR . $saveFileName; | ||
| file_put_contents($saveFilePath, $codeContent); | ||
|
|
||
| $uploadedFile = new UploadedFile( | ||
| $tempFilePath, | ||
| $tempFileName, | ||
| $saveFilePath, | ||
| $saveFileName, | ||
| 'application/octet-stream', | ||
| null, | ||
| true | ||
|
|
@@ -172,12 +171,12 @@ | |
| if (count($active_tab_array) == 1) { | ||
| $active_tab = reset($active_tab_array); | ||
| $this->dj->setCookie('active_tab', $active_tab); | ||
| } | ||
| else if ($this->dj->getCookie('active_tab') != null) { | ||
| $cookie_active_tab = $this->dj->getCookie('active_tab'); | ||
| if(in_array($cookie_active_tab, $active_tab_array)) { | ||
| $active_tab = $cookie_active_tab; | ||
| } | ||
| else { | ||
| $active_tab = reset($active_tab_array); | ||
| $this->dj->setCookie('active_tab', $active_tab); | ||
|
|
||