Example #1
0
 public function url()
 {
     $this->assertLoggedIn();
     $form = $this->_createUrlForm();
     $this->set('form', $form);
     $this->setTitle("Create Job from URL");
     if ($form->checkSubmitAndValidate($this->args())) {
         try {
             //did we get a url?
             $url = $this->args('url');
             if (!$url) {
                 if ($_SESSION['thing_url']) {
                     $url = $_SESSION['thing_url'];
                     unset($_SESSION['thing_url']);
                 } else {
                     throw new Exception("You didn't give us a URL");
                 }
             }
             if (preg_match("/thingiverse.com\\/thing:([0-9]+)/i", $url, $matches)) {
                 $file = $this->_handleThingiverseLinks($url);
             } else {
                 $tempFile = ServerFile::downloadFromUrl($url);
                 if ($tempFile === null) {
                     throw new Exception("We can't seem to access that file");
                 }
                 //does it match?
                 if (!$tempFile->isKnownType() && !$tempFile->isZip()) {
                     throw new Exception("The file <a href=\"" . $url . "\">{$tempFile->getName()}</a> is not valid for printing.");
                 }
                 $file = Storage::newFile();
                 $file->set('user_id', User::$me->id);
                 $file->set('source_url', $url);
                 $file->uploadNice($tempFile->getFile(), $tempFile->getName());
                 //is it a zip file?  do some magic on it.
                 if ($tempFile->isZip()) {
                     FileUploadHandler::_handleZipFile($tempFile->getFile(), $file);
                 }
             }
             Activity::log("uploaded a new file called " . $file->getLink() . ".");
             //send us to step 2.
             $this->forwardToUrl("/job/create/file:{$file->id}");
         } catch (Exception $e) {
             /** @var FormField $field */
             $field = $form->get('url');
             $field->error($e->getMessage());
         }
     }
 }
Example #2
0
 public function download_thing($thing_id)
 {
     $path = "/things/{$thing_id}/packageurl";
     $url = $this->make_call($path)->public_url;
     return ServerFile::downloadFromUrl($url);
 }